MessageHandler.c 719 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  73. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  74. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  75. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  76. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  77. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  78. static int TransactionMessageAttemptsValue = 0;
  79. static int TransactionMessageRetryIntervalValue = 0;
  80. static int TempMeterValueInterval = 0;
  81. static struct OCPPAuthLocalElemet
  82. {
  83. int listVersionInt;
  84. char idTagstr[20];
  85. char parentIdTag[20];
  86. char expiryDate[30];
  87. char idTagstatus[16];
  88. }idTagQuery;
  89. //=============================================
  90. // OCPP HeartBeat Response Not Receive Counts
  91. //============================================
  92. static int HeartBeatWithNOResponse = 0;
  93. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CONNECTOR_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. 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) &&
  422. (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))
  423. {
  424. //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);
  425. //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);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. 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))
  449. {
  450. //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);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. 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) &&
  472. (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))
  473. {
  474. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. 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);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. 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) &&
  562. (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))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. 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++)
  582. {
  583. 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"));
  584. 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")));
  585. 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?
  586. 3:
  587. 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")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. 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")));
  633. }
  634. else
  635. {
  636. 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));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. 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++)
  661. {
  662. 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"));
  663. 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")));
  664. 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?
  665. 3:
  666. 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")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. 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")));
  712. }
  713. else
  714. {
  715. 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));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. 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) &&
  794. (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))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. 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++)
  814. {
  815. 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"));
  816. 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")));
  817. 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?
  818. 3:
  819. 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")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. 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")));
  865. }
  866. else
  867. {
  868. 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));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. 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++)
  893. {
  894. 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"));
  895. 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")));
  896. 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?
  897. 3:
  898. 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")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. 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")));
  944. }
  945. else
  946. {
  947. 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));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. 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) &&
  1025. (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))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. 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++)
  1045. {
  1046. 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"));
  1047. 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")));
  1048. 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?
  1049. 3:
  1050. 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")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. 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")));
  1096. }
  1097. else
  1098. {
  1099. 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));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. 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++)
  1124. {
  1125. 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"));
  1126. 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")));
  1127. 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?
  1128. 3:
  1129. 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")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. 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")));
  1175. }
  1176. else
  1177. {
  1178. 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));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. 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);
  1229. 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);
  1230. 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);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. 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?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. 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?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. 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?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. 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?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. 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?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. 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?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1873. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1874. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1878. {
  1879. compositeProfile->ChargingProfileId = 1;
  1880. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1881. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1882. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1883. }
  1884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1885. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1886. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1887. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1888. }
  1889. if(line)
  1890. free(line);
  1891. }
  1892. //==========================================
  1893. // Init all share memory
  1894. //==========================================
  1895. int InitShareMemory()
  1896. {
  1897. int result = PASS;
  1898. int MeterSMId;
  1899. //creat ShmSysConfigAndInfo
  1900. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1901. {
  1902. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1903. result = FAIL;
  1904. }
  1905. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1906. {
  1907. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1908. result = FAIL;
  1909. }
  1910. else
  1911. {}
  1912. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1913. {
  1914. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1915. result = FAIL;
  1916. }
  1917. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1918. {
  1919. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1920. result = FAIL;
  1921. }
  1922. else
  1923. {}
  1924. //creat ShmPsuData
  1925. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1926. {
  1927. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1928. result = FAIL;
  1929. }
  1930. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1931. {
  1932. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1933. result = FAIL;
  1934. }
  1935. else
  1936. {}
  1937. //creat ShmOCPP16Data
  1938. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1939. {
  1940. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1941. result = FAIL;
  1942. }
  1943. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1944. {
  1945. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1946. result = FAIL;
  1947. }
  1948. else
  1949. {}
  1950. /****************************** For Initial Settings************************************************/
  1951. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1952. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1953. // allocate Configuration memory address
  1954. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1955. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1957. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1958. //offline MeterValue Interval
  1959. TempMeterValueInterval = 0;
  1960. return result;
  1961. }
  1962. int ProcessShareMemory()
  1963. {
  1964. if(InitShareMemory() == FAIL)
  1965. {
  1966. DEBUG_ERROR("InitShareMemory NG\n");
  1967. if(ShmStatusCodeData!=NULL)
  1968. {
  1969. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1970. }
  1971. sleep(5);
  1972. return FAIL;
  1973. }
  1974. return PASS;
  1975. }
  1976. //---------------------common routine---------------------------//
  1977. int isOFFline(void)
  1978. {
  1979. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1980. {
  1981. if(TempMeterValueInterval >= 2 )
  1982. {
  1983. TempMeterValueInterval = 0;
  1984. return TRUE;
  1985. }
  1986. else
  1987. {
  1988. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1989. return FALSE;
  1990. }
  1991. }
  1992. else
  1993. {
  1994. return FALSE;
  1995. }
  1996. }
  1997. //---------------------------------------------
  1998. // new:
  1999. // enum SYSTEM_STATUS
  2000. // {
  2001. // SYS_MODE_BOOTING = 0,
  2002. // SYS_MODE_IDLE = 1,
  2003. // SYS_MODE_AUTHORIZING = 2,
  2004. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2005. // SYS_MODE_REASSIGN = 4,
  2006. // SYS_MODE_PREPARING = 5,
  2007. // SYS_MODE_PREPARE_FOR_EV = 6,
  2008. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2009. // SYS_MODE_CHARGING = 8,
  2010. // SYS_MODE_TERMINATING = 9,
  2011. // SYS_MODE_COMPLETE = 10,
  2012. // SYS_MODE_ALARM = 11,
  2013. // SYS_MODE_FAULT = 12,
  2014. // SYS_MODE_RESERVATION = 13,
  2015. // SYS_MODE_BOOKING = 14,
  2016. // SYS_MODE_MAINTAIN = 15,
  2017. // SYS_MODE_DEBUG = 16,
  2018. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2020. // SYS_MODE_UPDATE = 19
  2021. // };
  2022. //
  2023. //
  2024. //-----------------------------------------
  2025. void CheckSystemValue(void)
  2026. {
  2027. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2028. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2029. char filenmae[100]={0};
  2030. char str[100]={0};
  2031. int tempIndex = 0;
  2032. //===============================
  2033. // send Heartbeat
  2034. //===============================
  2035. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2036. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2037. {
  2038. clientTime.Heartbeat=time((time_t*)NULL);
  2039. if(server_sign == TRUE)
  2040. {
  2041. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2042. }
  2043. else
  2044. {
  2045. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2046. }
  2047. }
  2048. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2049. {
  2050. //parameter for test
  2051. sendHeartbeatRequest(0);
  2052. //==============================================
  2053. // Reset Waiting Time
  2054. //==============================================
  2055. HeartBeatWithNOResponse += 1;
  2056. }
  2057. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2058. {
  2059. //===============================
  2060. // CSU Trigger Reset Conf
  2061. //===============================
  2062. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2063. {
  2064. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2065. }
  2066. //===============================
  2067. // CSU Trigger Authorize Request
  2068. //===============================
  2069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2070. {
  2071. sendAuthorizeRequest(0);
  2072. authorizeRetryTimes = authorizeRetryTimes + 1;
  2073. if(authorizeRetryTimes < 3)
  2074. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2075. }
  2076. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2077. {
  2078. authorizeRetryTimes = 0;
  2079. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2080. server_sign = FALSE;
  2081. }
  2082. 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))
  2083. {
  2084. sendAuthorizeRequest(0);
  2085. }
  2086. //===============================
  2087. // CSU Trigger Smart Charging Profilw
  2088. //===============================
  2089. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2090. {
  2091. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2092. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2093. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2094. }
  2095. //==============================================
  2096. // Charger start transaction
  2097. //==============================================
  2098. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2099. {
  2100. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2101. sendStartTransactionRequest(gun_index);
  2102. clientTime.StartTransaction = time((time_t*)NULL);
  2103. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2104. }
  2105. //==============================================
  2106. // Charger stop transaction
  2107. //==============================================
  2108. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2109. {
  2110. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2111. sendStopTransactionRequest(gun_index);
  2112. clientTime.StopTransaction = time((time_t*)NULL);
  2113. }
  2114. //==============================================
  2115. // Charger status report
  2116. //==============================================
  2117. //--- Check Mode Change ---//
  2118. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2119. if(gunType[gun_index] == 'J')
  2120. {
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2122. {
  2123. tempIndex = ((gun_index==2) ? 1: 0);
  2124. }
  2125. else
  2126. {
  2127. tempIndex = gun_index;
  2128. }
  2129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2130. {
  2131. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2132. {
  2133. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2134. {
  2135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2138. statusModeChage[gun_index] = TRUE;
  2139. }
  2140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2141. {
  2142. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2143. if((access(filenmae,F_OK))!=-1)
  2144. {
  2145. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2146. sprintf(str,"rm -f %s",filenmae);
  2147. system(str);
  2148. }
  2149. }
  2150. #if 1 // for TempStopTransaction
  2151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2152. {
  2153. checkTempStopTransaction(gun_index);
  2154. }
  2155. #endif
  2156. }
  2157. }
  2158. }
  2159. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2160. {
  2161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2162. {
  2163. tempIndex = ((gun_index==2) ? 1: 0);
  2164. }
  2165. else
  2166. {
  2167. tempIndex = gun_index;
  2168. }
  2169. for (int index = 0; index < CCS_QUANTITY; index++)
  2170. {
  2171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2172. {
  2173. 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]*/ )
  2174. {
  2175. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2176. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2177. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2178. statusModeChage[gun_index] = TRUE;
  2179. }
  2180. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2181. {
  2182. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2183. if((access(filenmae,F_OK))!=-1)
  2184. {
  2185. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2186. sprintf(str,"rm -f %s",filenmae);
  2187. system(str);
  2188. }
  2189. }
  2190. #if 1 // for TempStopTransaction
  2191. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2192. {
  2193. checkTempStopTransaction(gun_index);
  2194. }
  2195. #endif
  2196. }
  2197. }
  2198. }
  2199. else if(gunType[gun_index] == 'G')
  2200. {
  2201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2202. {
  2203. tempIndex = ((gun_index==2) ? 1: 0);
  2204. }
  2205. else
  2206. {
  2207. tempIndex = gun_index;
  2208. }
  2209. for (int index = 0; index < GB_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2212. {
  2213. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2214. {
  2215. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2216. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2217. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2218. statusModeChage[gun_index] = TRUE;
  2219. }
  2220. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2221. {
  2222. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2223. if((access(filenmae,F_OK))!=-1)
  2224. {
  2225. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2226. sprintf(str,"rm -f %s",filenmae);
  2227. system(str);
  2228. }
  2229. }
  2230. #if 1 // for TempStopTransaction
  2231. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2232. {
  2233. checkTempStopTransaction(gun_index);
  2234. }
  2235. #endif
  2236. }
  2237. }
  2238. }
  2239. else if(gunType[gun_index] == 'O')
  2240. {
  2241. tempIndex = gun_index;
  2242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2243. {
  2244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2245. {
  2246. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2247. {
  2248. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2249. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2250. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2251. statusModeChage[gun_index] = TRUE;
  2252. }
  2253. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  2254. {
  2255. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2256. if((access(filenmae,F_OK))!=-1)
  2257. {
  2258. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2259. sprintf(str,"rm -f %s",filenmae);
  2260. system(str);
  2261. }
  2262. }
  2263. #if 1 // for TempStopTransaction
  2264. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2265. {
  2266. checkTempStopTransaction(gun_index);
  2267. }
  2268. #endif
  2269. }
  2270. }
  2271. }
  2272. else
  2273. {
  2274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2275. {
  2276. tempIndex = 2;
  2277. }
  2278. else
  2279. {
  2280. tempIndex = gun_index;
  2281. }
  2282. for (int index = 0; index < AC_QUANTITY; index++)
  2283. {
  2284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2285. {
  2286. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2287. {
  2288. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2289. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2290. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2291. statusModeChage[gun_index] = TRUE;
  2292. }
  2293. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2294. {
  2295. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2296. if((access(filenmae,F_OK))!=-1)
  2297. {
  2298. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2299. sprintf(str,"rm -f %s",filenmae);
  2300. system(str);
  2301. }
  2302. }
  2303. #if 1 // for TempStopTransaction
  2304. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2305. {
  2306. checkTempStopTransaction(gun_index);
  2307. }
  2308. #endif
  2309. }
  2310. }// END
  2311. }
  2312. if(isWebsocketSendable &&
  2313. (((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10)))) )
  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. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2325. {
  2326. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2327. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2328. }
  2329. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2330. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2331. {
  2332. //check Transaction active
  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. reqSampleMeter[gun_index] = 1;
  2351. }
  2352. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2353. {
  2354. reqClockAlignMeter[gun_index] = 1;
  2355. }
  2356. }
  2357. }// End for CHAdeMO
  2358. }
  2359. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2360. {
  2361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2362. {
  2363. tempIndex = ((gun_index==2) ? 1: 0);
  2364. }
  2365. else
  2366. {
  2367. tempIndex = gun_index;
  2368. }
  2369. for (int index = 0; index < CCS_QUANTITY; index++)
  2370. {
  2371. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2373. {
  2374. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2375. {
  2376. reqSampleMeter[gun_index] = 1;
  2377. }
  2378. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2379. {
  2380. reqClockAlignMeter[gun_index] = 1;
  2381. }
  2382. }
  2383. } // End for CCS
  2384. }
  2385. else if(gunType[gun_index] == 'G')
  2386. {
  2387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2388. {
  2389. tempIndex = ((gun_index==2) ? 1: 0);
  2390. }
  2391. else
  2392. {
  2393. tempIndex = gun_index;
  2394. }
  2395. for (int index = 0; index < GB_QUANTITY; index++)
  2396. {
  2397. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2398. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2399. {
  2400. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2401. {
  2402. reqSampleMeter[gun_index] = 1;
  2403. }
  2404. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2405. {
  2406. reqClockAlignMeter[gun_index] = 1;
  2407. }
  2408. }
  2409. }// End for GB
  2410. }
  2411. else if(gunType[gun_index] == 'O')
  2412. {
  2413. tempIndex = gun_index;
  2414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2415. {
  2416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2417. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2418. {
  2419. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2420. {
  2421. reqSampleMeter[gun_index] = 1;
  2422. }
  2423. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2424. {
  2425. reqClockAlignMeter[gun_index] = 1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2433. {
  2434. tempIndex = 2;
  2435. }
  2436. else
  2437. {
  2438. tempIndex = gun_index;
  2439. }
  2440. for (int index = 0; index < AC_QUANTITY; index++)
  2441. {
  2442. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2443. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2444. {
  2445. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2446. {
  2447. reqSampleMeter[gun_index] = 1;
  2448. }
  2449. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2450. {
  2451. reqClockAlignMeter[gun_index] = 1;
  2452. }
  2453. }
  2454. }//End for AC
  2455. }
  2456. if(reqSampleMeter[gun_index] == 1)
  2457. {
  2458. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2459. storeTempStopTransaction(gun_index);
  2460. }
  2461. else if(reqClockAlignMeter[gun_index] == 1)
  2462. {
  2463. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2464. }
  2465. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2466. sleep(1);
  2467. }
  2468. //==============================================
  2469. // Check Connector reserved
  2470. //==============================================
  2471. //===============================
  2472. // Check if Reserve is expired
  2473. //===============================
  2474. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2475. {
  2476. double diff_t;
  2477. struct tm tp;
  2478. // current time
  2479. time_t t = time(NULL);
  2480. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2481. tp.tm_isdst = -1;
  2482. time_t utc = mktime(&tp);
  2483. diff_t = difftime(utc, t);
  2484. if(diff_t <= 0)
  2485. {
  2486. DEBUG_INFO("reserve expired.\n");
  2487. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2488. }
  2489. }//END OF Check if Reserve is expired
  2490. //==========================================
  2491. // csu trigger FirmwareStatusNotificationReq
  2492. //==========================================
  2493. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2494. {
  2495. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2496. }
  2497. //==========================================
  2498. // csu trigger CancelReservationConf
  2499. //==========================================
  2500. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2501. {
  2502. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2503. }
  2504. //==========================================
  2505. // csu trigger ChangeAvailabilityConf
  2506. //==========================================
  2507. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2508. {
  2509. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2510. }
  2511. //==========================================
  2512. // csu trigger UnlockConnectorConf
  2513. //==========================================
  2514. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2515. {
  2516. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2517. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2518. }
  2519. //==========================================
  2520. // csu trigger ReserveNowConf
  2521. //==========================================
  2522. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2523. {
  2524. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2525. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2526. }
  2527. //==========================================
  2528. // csu trigger DataTransferReq
  2529. //==========================================
  2530. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2531. {
  2532. sendDataTransferRequest(gun_index);
  2533. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2534. }
  2535. }
  2536. }
  2537. //==========================================
  2538. // send request routine
  2539. //==========================================
  2540. int sendAuthorizeRequest(int gun_index)
  2541. {
  2542. mtrace();
  2543. int result = FAIL;
  2544. char message[100]={0};
  2545. char guid[37];
  2546. char tempdata[65]={0};
  2547. DEBUG_INFO("sendAuthorizeRequest...\n");
  2548. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2549. //Local Authorize
  2550. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2551. {
  2552. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2553. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2554. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2555. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2556. result = PASS;
  2557. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2558. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2559. authorizeRetryTimes = 0;
  2560. return result;
  2561. }
  2562. 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))||
  2563. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2564. {
  2565. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2566. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2567. {
  2568. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2569. {
  2570. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2571. }
  2572. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2573. {
  2574. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2575. }
  2576. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2577. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2578. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2579. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2580. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2581. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2582. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2583. authorizeRetryTimes = 0;
  2584. return result;
  2585. }
  2586. else
  2587. {
  2588. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2589. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2590. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2591. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2592. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2593. else
  2594. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2595. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2596. result = PASS;
  2597. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2598. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2599. authorizeRetryTimes = 0;
  2600. return result;
  2601. }
  2602. }
  2603. //initailize struct Authorize
  2604. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2605. //get data from shared memory
  2606. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2607. random_uuid(guid);
  2608. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2609. LWS_Send(message);
  2610. sprintf(tempdata, "Authorize,%d", gun_index);
  2611. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2612. {
  2613. result = PASS;
  2614. DEBUG_INFO("Authorize mapItem pass\n");
  2615. }
  2616. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2617. return result;
  2618. }
  2619. int sendBootNotificationRequest(void)
  2620. {
  2621. mtrace();
  2622. int result = FAIL;
  2623. char message[500]={0}, payload[700]={0};
  2624. char guid[37]={0};
  2625. char tempdata[65]={0};
  2626. /*
  2627. int IsGunCharging = FALSE;
  2628. //check Transaction active
  2629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2630. {
  2631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2632. {
  2633. IsGunCharging = TRUE;
  2634. }
  2635. }
  2636. for (int index = 0; index < CCS_QUANTITY; index++)
  2637. {
  2638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2639. {
  2640. IsGunCharging = TRUE;
  2641. }
  2642. }
  2643. for (int index = 0; index < GB_QUANTITY; index++)
  2644. {
  2645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2646. {
  2647. IsGunCharging = TRUE;
  2648. }
  2649. }
  2650. for (int index = 0; index < AC_QUANTITY; index++)
  2651. {
  2652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2653. {
  2654. IsGunCharging = TRUE;
  2655. }
  2656. }
  2657. if(IsGunCharging == TRUE)
  2658. {
  2659. server_sign = TRUE;
  2660. return result;
  2661. }
  2662. */
  2663. // Fill BootNotification fields
  2664. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2665. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2666. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2667. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2668. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2669. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2670. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2671. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2672. ShmOCPP16Data->ChargeBoxId
  2673. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2674. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2675. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2676. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2677. ,ShmOCPP16Data->BootNotification.CpIccid
  2678. ,ShmOCPP16Data->BootNotification.CpImsi);
  2679. random_uuid(guid);
  2680. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2681. LWS_Send(message);
  2682. sprintf(tempdata, "BootNotification,0");
  2683. 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*/)
  2684. {
  2685. result = PASS;
  2686. }
  2687. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2688. strcpy(queuedata,message);
  2689. return result;
  2690. }
  2691. int sendDataTransferRequest(int gun_index)
  2692. {
  2693. mtrace();
  2694. char message[1000]={0};
  2695. char guid[37]={0};
  2696. char tempdata[65]={0};
  2697. int result = FAIL;
  2698. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2699. random_uuid(guid);
  2700. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2701. MESSAGE_TYPE_CALL,
  2702. guid,
  2703. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2704. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2705. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2706. LWS_Send(message);
  2707. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2708. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2709. {
  2710. result = PASS;
  2711. DEBUG_INFO("DataTransfer mapItem pass\n");
  2712. }
  2713. return result;
  2714. }
  2715. int sendDiagnosticsStatusNotificationRequest(char *status)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[110]={0};
  2720. char guid[37]={0};
  2721. char tempdata[65]={0};
  2722. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2723. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2724. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2725. random_uuid(guid);
  2726. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2727. LWS_SendNow(message);
  2728. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2729. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2730. {
  2731. result = PASS;
  2732. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2733. }
  2734. //#ifdef SystemLogMessage
  2735. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2736. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2737. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2738. //#endif
  2739. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2740. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2741. //record status
  2742. if(strcmp(status,"Idle")==0)
  2743. {
  2744. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2745. }
  2746. else if(strcmp(status,"Uploaded")==0)
  2747. {
  2748. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2749. }
  2750. else if(strcmp(status,"UploadFailed")==0)
  2751. {
  2752. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2753. }
  2754. else if(strcmp(status,"Uploading")==0)
  2755. {
  2756. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2757. }
  2758. return result;
  2759. }
  2760. int sendFirmwareStatusNotificationRequest(char *status)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[110]={0};
  2765. char guid[37]={0};
  2766. char tempdata[65]={0};
  2767. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2768. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2769. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2770. random_uuid(guid);
  2771. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2772. LWS_SendNow(message);
  2773. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2774. 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*/)
  2775. {
  2776. result = PASS;
  2777. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2778. }
  2779. //#ifdef SystemLogMessage
  2780. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2781. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2782. //#endif
  2783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2784. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2785. //record status
  2786. if(strcmp(status,"Downloaded")==0)
  2787. {
  2788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2789. }
  2790. else if(strcmp(status,"DownloadFailed")==0)
  2791. {
  2792. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2793. }
  2794. else if(strcmp(status,"Downloading")==0)
  2795. {
  2796. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2797. }
  2798. else if(strcmp(status,"Idle")==0)
  2799. {
  2800. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2801. }
  2802. else if(strcmp(status,"InstallationFailed")==0)
  2803. {
  2804. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2805. }
  2806. else if(strcmp(status,"Installing")==0)
  2807. {
  2808. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2809. }
  2810. else if(strcmp(status,"Installed")==0)
  2811. {
  2812. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2813. }
  2814. return result;
  2815. }
  2816. int sendHeartbeatRequest(int gun_index)
  2817. {
  2818. mtrace();
  2819. int result = FAIL;
  2820. char message[80]={0};
  2821. char guid[37]={0};
  2822. char tempdata[65]={0};
  2823. random_uuid(guid);
  2824. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2825. , MESSAGE_TYPE_CALL
  2826. , guid );
  2827. LWS_Send(message);
  2828. sprintf(tempdata, "Heartbeat,%d", 0);
  2829. 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*/)
  2830. {
  2831. result = PASS;
  2832. }
  2833. return result;
  2834. }
  2835. int sendStartTransactionRequest(int gun_index)
  2836. {
  2837. mtrace();
  2838. int result = FAIL;
  2839. char message[250]={0};
  2840. char guid[37]={0};
  2841. struct timeval tmnow;
  2842. struct tm *tm;
  2843. char buf[28];//, usec_buf[6];
  2844. char tempdata[65]={0};
  2845. int tempIndex = 0;
  2846. DEBUG_INFO("sendStartTransactionRequest...\n");
  2847. gettimeofday(&tmnow, NULL);
  2848. time_t t;
  2849. t = time(NULL);
  2850. /*UTC time and date*/
  2851. tm = gmtime(&t);
  2852. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2853. #if 0 // remove temporally
  2854. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2855. strcat(buf,".");
  2856. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2857. strcat(buf,usec_buf);
  2858. #endif
  2859. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2860. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2861. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2862. // clear StartTransaction Response
  2863. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2864. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2865. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2866. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2867. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2868. if(gunType[gun_index] == 'J')
  2869. {
  2870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2871. {
  2872. tempIndex = ((gun_index==2) ? 1: 0);
  2873. }
  2874. else
  2875. {
  2876. tempIndex = gun_index;
  2877. }
  2878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2879. {
  2880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2881. {
  2882. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2883. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2884. }
  2885. }
  2886. }
  2887. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2888. {
  2889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2890. {
  2891. tempIndex = ((gun_index==2) ? 1: 0);
  2892. }
  2893. else
  2894. {
  2895. tempIndex = gun_index;
  2896. }
  2897. for (int index = 0; index < CCS_QUANTITY; index++)
  2898. {
  2899. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2900. {
  2901. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2902. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2903. }
  2904. }
  2905. }
  2906. else if(gunType[gun_index] == 'G')
  2907. {
  2908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2909. {
  2910. tempIndex = ((gun_index==2) ? 1: 0);
  2911. }
  2912. else
  2913. {
  2914. tempIndex = gun_index;
  2915. }
  2916. for (int index = 0; index < GB_QUANTITY; index++)
  2917. {
  2918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2919. {
  2920. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2921. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2922. }
  2923. }
  2924. }
  2925. else if(gunType[gun_index] == 'O')
  2926. {
  2927. tempIndex = gun_index;
  2928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2929. {
  2930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2931. {
  2932. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  2933. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  2934. }
  2935. }
  2936. }
  2937. else
  2938. {
  2939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2940. {
  2941. tempIndex = 2;
  2942. }
  2943. else
  2944. {
  2945. tempIndex = gun_index;
  2946. }
  2947. for (int index = 0; index < AC_QUANTITY; index++)
  2948. {
  2949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2950. {
  2951. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2952. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2953. }
  2954. }
  2955. }
  2956. random_uuid(guid);
  2957. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2958. {
  2959. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2960. , gun_index +1
  2961. , MESSAGE_TYPE_CALL
  2962. , guid
  2963. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2964. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2965. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2966. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2967. }
  2968. else
  2969. {
  2970. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2971. , gun_index +1
  2972. , MESSAGE_TYPE_CALL
  2973. , guid
  2974. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2975. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2976. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2977. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2978. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2979. }
  2980. #if 1
  2981. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2982. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2983. {
  2984. result = PASS;
  2985. }
  2986. #endif
  2987. strcpy(queuedata, message);
  2988. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2989. return result;
  2990. }
  2991. int sendStatusNotificationRequest(int gun_index)
  2992. {
  2993. mtrace();
  2994. int result = FAIL;
  2995. char message[600]={0};
  2996. char guid[37];
  2997. int currentStatus = 0;
  2998. struct timeval tmnow;
  2999. struct tm *tm;
  3000. char buf[28];//, usec_buf[6];
  3001. char tempdata[65]={0};
  3002. int tempIndex = 0;
  3003. gettimeofday(&tmnow, NULL);
  3004. time_t t;
  3005. t = time(NULL);
  3006. /*UTC time and date*/
  3007. tm = gmtime(&t);
  3008. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3009. #if 0 // remove temporally
  3010. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3011. strcat(buf,".");
  3012. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3013. strcat(buf,usec_buf);
  3014. #endif
  3015. printf("%s",buf);
  3016. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3017. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3018. // it's option
  3019. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3020. /*
  3021. enum _SYSTEM_STATUS
  3022. {
  3023. S_BOOTING = 0,
  3024. S_IDLE, = 1
  3025. S_AUTHORIZING, =2
  3026. S_REASSIGN_CHECK, =3
  3027. S_REASSIGN, =4
  3028. S_PRECHARGE, =5
  3029. S_PREPARING_FOR_EV, =6
  3030. S_PREPARING_FOR_EVSE, =7
  3031. S_CHARGING, =8
  3032. S_TERMINATING, =9
  3033. S_COMPLETE, =10
  3034. S_ALARM, =11
  3035. S_FAULT =12
  3036. }
  3037. */
  3038. //check Transaction active
  3039. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3040. if(gunType[gun_index] == 'J')
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3051. {
  3052. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3053. {
  3054. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3055. {
  3056. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3057. {
  3058. currentStatus = 1; //OCPP Status: Preparing
  3059. }
  3060. else
  3061. {
  3062. currentStatus = 0; //OCPP Status: Available
  3063. }
  3064. }
  3065. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3066. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3067. ) //S_PRECHARGE
  3068. {
  3069. currentStatus = 1; //OCPP Status: Preparing
  3070. }
  3071. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3072. {
  3073. currentStatus = 2; //OCPP Status: Charging
  3074. }
  3075. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3076. {
  3077. currentStatus = 5; //OCPP Status: Finishing
  3078. }
  3079. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3080. {
  3081. currentStatus = 4; //OCPP Status: SuspendedEV
  3082. }
  3083. 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
  3084. {
  3085. currentStatus = 7; //OCPP Status: Unavailable
  3086. }
  3087. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3088. {
  3089. currentStatus = 8; //OCPP Status: Faulted
  3090. }
  3091. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3092. {
  3093. currentStatus = 6; //OCPP Status: Reserved
  3094. }
  3095. } //end of the same index
  3096. }//end of for CHAdeMO_QUANTITY
  3097. }
  3098. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3109. {
  3110. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3111. {
  3112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3113. {
  3114. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[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.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3130. {
  3131. currentStatus = 2; //OCPP Status: Charging
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3134. {
  3135. currentStatus = 5; //OCPP Status: Finishing
  3136. }
  3137. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3138. {
  3139. currentStatus = 4; //OCPP Status: SuspendedEV
  3140. }
  3141. 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
  3142. {
  3143. currentStatus = 7; //OCPP Status : Unavailable
  3144. }
  3145. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3146. {
  3147. currentStatus = 8; //OCPP Status: Faulted
  3148. }
  3149. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3150. {
  3151. currentStatus = 6; //OCPP Status: Reserved
  3152. }
  3153. } //end of the same index
  3154. } // end of for CCS_QUANTITY
  3155. }
  3156. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3167. {
  3168. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3171. {
  3172. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[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.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3188. {
  3189. currentStatus = 2; //OCPP Status: Charging
  3190. }
  3191. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3192. {
  3193. currentStatus = 5; //OCPP Status: Finishing
  3194. }
  3195. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3196. {
  3197. currentStatus = 4; //OCPP Status: SuspendedEV
  3198. }
  3199. 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
  3200. {
  3201. currentStatus = 7; //OCPP Status: Unavailable
  3202. }
  3203. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3204. {
  3205. currentStatus = 8; //OCPP Status: Faulted
  3206. }
  3207. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3208. {
  3209. currentStatus = 6; //OCPP Status: Reserved
  3210. }
  3211. } //end of the same index
  3212. } // end of for GB_QUANTITY
  3213. }
  3214. else if(gunType[gun_index] == 'O')
  3215. {
  3216. tempIndex = gun_index;
  3217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3218. {
  3219. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3220. {
  3221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3222. {
  3223. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3224. {
  3225. currentStatus = 1; //OCPP Status: Preparing
  3226. }
  3227. else
  3228. {
  3229. currentStatus = 0; //OCPP Status: Available
  3230. }
  3231. }
  3232. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3233. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3234. ) //S_PRECHARGE
  3235. {
  3236. currentStatus = 1; //OCPP Status: Preparing
  3237. }
  3238. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3239. {
  3240. currentStatus = 2; //OCPP Status: Charging
  3241. }
  3242. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3243. {
  3244. currentStatus = 5; //OCPP Status: Finishing
  3245. }
  3246. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3247. {
  3248. currentStatus = 4; //OCPP Status: SuspendedEV
  3249. }
  3250. 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
  3251. {
  3252. currentStatus = 7; //OCPP Status: Unavailable
  3253. }
  3254. 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
  3255. {
  3256. currentStatus = 8; //OCPP Status: Faulted
  3257. }
  3258. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3259. {
  3260. currentStatus = 6; //OCPP Status: Reserved
  3261. }
  3262. } //end of the same index
  3263. }
  3264. }
  3265. else
  3266. {
  3267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3268. {
  3269. tempIndex = 2;
  3270. }
  3271. else
  3272. {
  3273. tempIndex = gun_index;
  3274. }
  3275. for (int index = 0; index < AC_QUANTITY; index++)
  3276. {
  3277. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3278. {
  3279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3280. {
  3281. 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))
  3282. {
  3283. currentStatus = 1; //OCPP Status: Preparing
  3284. }
  3285. else
  3286. {
  3287. currentStatus = 0; //OCPP Status: Available
  3288. }
  3289. }
  3290. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3291. {
  3292. currentStatus = 1; //OCPP Status: Preparing
  3293. }
  3294. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3295. {
  3296. currentStatus = 2; //OCPP Status: Charging
  3297. }
  3298. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3299. {
  3300. currentStatus = 5; //OCPP Status: Finishing
  3301. }
  3302. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3303. {
  3304. currentStatus = 4; //OCPP Status: SuspendedEV
  3305. }
  3306. 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
  3307. {
  3308. currentStatus = 7; //OCPP Status: Unavailable
  3309. }
  3310. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3311. {
  3312. currentStatus = 8; //OCPP Status: Faulted
  3313. }
  3314. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3315. {
  3316. currentStatus = 6; //OCPP Status: Reserved
  3317. }
  3318. }//end of the same index
  3319. }//end of for AC_QUANTITY
  3320. }
  3321. //it's option
  3322. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3323. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3325. random_uuid(guid);
  3326. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3327. , MESSAGE_TYPE_CALL
  3328. , guid
  3329. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3330. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3331. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3332. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3333. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3334. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3335. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3336. if((server_sign == TRUE))
  3337. {
  3338. LWS_Send(message);
  3339. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3340. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3341. {
  3342. //DEBUG_ERROR("statusNotification mapitem pass");
  3343. result = PASS;
  3344. }
  3345. }
  3346. else
  3347. {
  3348. result = PASS;
  3349. }
  3350. return result;
  3351. }
  3352. int sendStopTransactionRequest(int gun_index)
  3353. {
  3354. mtrace();
  3355. int result = FAIL;
  3356. //char message[1500]={0};
  3357. char guid[37]={0};
  3358. char tempdata[65]={0};
  3359. int tempIndex = 0;
  3360. char TempStopTransaction[256];
  3361. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3362. //int idx_sample=0;
  3363. DEBUG_INFO("sendStopTransactionRequest \n");
  3364. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3365. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3366. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3367. if(gunType[gun_index] == 'J')
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3370. {
  3371. tempIndex = ((gun_index==2) ? 1: 0);
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3380. {
  3381. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3382. }
  3383. }// END OF CHAdeMO_QUANTITY
  3384. }
  3385. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3386. {
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3388. {
  3389. tempIndex = ((gun_index==2) ? 1: 0);
  3390. }
  3391. else
  3392. {
  3393. tempIndex = gun_index;
  3394. }
  3395. for (int index = 0; index < CCS_QUANTITY; index++)
  3396. {
  3397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3398. {
  3399. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3400. }
  3401. }// END OF CCS_QUANTITY
  3402. }
  3403. else if(gunType[gun_index] == 'G')
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3406. {
  3407. tempIndex = ((gun_index==2) ? 1: 0);
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < GB_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3416. {
  3417. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3418. }
  3419. }// END OF GB_QUANTITY
  3420. }
  3421. else if(gunType[gun_index] == 'O')
  3422. {
  3423. tempIndex = gun_index;
  3424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3425. {
  3426. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3427. {
  3428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3429. }
  3430. }// END OF GB_QUANTITY
  3431. }
  3432. else
  3433. {
  3434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3435. {
  3436. tempIndex = 2;
  3437. }
  3438. else
  3439. {
  3440. tempIndex = gun_index;
  3441. }
  3442. for (int index = 0; index < AC_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3445. {
  3446. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3447. }
  3448. }// END OF AC_QUANTITY
  3449. }
  3450. //====================================== Stop Transaction Time =====================================================
  3451. struct timeval tmnow;
  3452. struct tm *tm;
  3453. char buf[28];//, usec_buf[6];
  3454. gettimeofday(&tmnow, NULL);
  3455. time_t t;
  3456. t = time(NULL);
  3457. /*UTC time and date*/
  3458. tm = gmtime(&t);
  3459. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3461. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3462. random_uuid(guid);
  3463. /***********************************transactionData******************************************************/
  3464. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3466. //=================================
  3467. // Transaction_Begin
  3468. //=================================
  3469. //============================================ Energy.Active.Import.Interval ================================
  3470. //idx_sample=0;
  3471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3474. 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*/]);
  3475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3476. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3477. {
  3478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3479. }
  3480. else
  3481. {
  3482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3483. }
  3484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3486. //=================================
  3487. // Transaction_End
  3488. //=================================
  3489. // ================================= Current.Import L1 ===============================================
  3490. //idx_sample=1;
  3491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3492. if(gunType[gun_index] == 'J')
  3493. {
  3494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3495. {
  3496. tempIndex = ((gun_index==2) ? 1: 0);
  3497. }
  3498. else
  3499. {
  3500. tempIndex = gun_index;
  3501. }
  3502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3503. {
  3504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3505. {
  3506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3507. }
  3508. }// End of for CHAdeMO_QUANTITY
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3510. }
  3511. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3514. {
  3515. tempIndex = ((gun_index==2) ? 1: 0);
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < CCS_QUANTITY; index++)
  3522. {
  3523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3524. {
  3525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3526. }
  3527. }// End of for CCS_QUANTITY
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3529. }
  3530. else if(gunType[gun_index] == 'G')
  3531. {
  3532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3533. {
  3534. tempIndex = ((gun_index==2) ? 1: 0);
  3535. }
  3536. else
  3537. {
  3538. tempIndex = gun_index;
  3539. }
  3540. for (int index = 0; index < GB_QUANTITY; index++)
  3541. {
  3542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3543. {
  3544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3545. }
  3546. }// End of for GB_QUANTITY
  3547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3548. }
  3549. else if(gunType[gun_index] == 'O')
  3550. {
  3551. tempIndex = gun_index;
  3552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3553. {
  3554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3555. {
  3556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3557. }
  3558. }
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3560. }
  3561. else
  3562. {
  3563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3564. {
  3565. tempIndex = 2;
  3566. }
  3567. else
  3568. {
  3569. tempIndex = gun_index;
  3570. }
  3571. for (int index = 0; index < AC_QUANTITY; index++)
  3572. {
  3573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3574. {
  3575. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3576. }
  3577. }// End of for AC_QUANTITY
  3578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3579. }
  3580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3585. // ================================= Energy.Active.Import.Interval ==============================================
  3586. //idx_sample=2;
  3587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3588. if(gunType[gun_index] == 'J')
  3589. {
  3590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3591. {
  3592. tempIndex = ((gun_index==2) ? 1: 0);
  3593. }
  3594. else
  3595. {
  3596. tempIndex = gun_index;
  3597. }
  3598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3599. {
  3600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3601. {
  3602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3603. }
  3604. }// END OF CHAdeMO_QUANTITY
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3606. }
  3607. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3608. {
  3609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3610. {
  3611. tempIndex = ((gun_index==2) ? 1: 0);
  3612. }
  3613. else
  3614. {
  3615. tempIndex = gun_index;
  3616. }
  3617. for (int index = 0; index < CCS_QUANTITY; index++)
  3618. {
  3619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3620. {
  3621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3622. }
  3623. }// END OF CCS_QUANTITY
  3624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3625. }
  3626. else if(gunType[gun_index] == 'G')
  3627. {
  3628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3629. {
  3630. tempIndex = ((gun_index==2) ? 1: 0);
  3631. }
  3632. else
  3633. {
  3634. tempIndex = gun_index;
  3635. }
  3636. for (int index = 0; index < GB_QUANTITY; index++)
  3637. {
  3638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3639. {
  3640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3641. }
  3642. }// END OF GB_QUANTITY
  3643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3644. }
  3645. else if(gunType[gun_index] == 'O')
  3646. {
  3647. tempIndex = gun_index;
  3648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3651. {
  3652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3653. }
  3654. }
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3656. }
  3657. else
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3660. {
  3661. tempIndex = 2;
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < AC_QUANTITY; index++)
  3668. {
  3669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3670. {
  3671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3672. }
  3673. }// END OF AC_QUANTITY
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3675. }
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3681. //=================================== Power.Active.Import ==================================================
  3682. //idx_sample=3;
  3683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3684. if(gunType[gun_index] == 'J')
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3695. {
  3696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3697. {
  3698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3699. }
  3700. } // End for CHAdeMO_QUANTITY
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3702. }
  3703. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3716. {
  3717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3718. }
  3719. } // END for CCS_QUANTITY
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3721. }
  3722. else if(gunType[gun_index] == 'G')
  3723. {
  3724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3725. {
  3726. tempIndex = ((gun_index==2) ? 1: 0);
  3727. }
  3728. else
  3729. {
  3730. tempIndex = gun_index;
  3731. }
  3732. for (int index = 0; index < GB_QUANTITY; index++)
  3733. {
  3734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3735. {
  3736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3737. }
  3738. }// END for GB_QUANTITY
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3740. }
  3741. else if(gunType[gun_index] == 'O')
  3742. {
  3743. tempIndex = gun_index;
  3744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3747. {
  3748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3749. }
  3750. }
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3752. }
  3753. else
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3756. {
  3757. tempIndex = 2;
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < AC_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3766. {
  3767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3768. }
  3769. } // END for AC_QUANTITY
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3771. }
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3777. //============================ Voltage L1 ====================================
  3778. //idx_sample=4;
  3779. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3780. if(gunType[gun_index] == 'J')
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3783. {
  3784. tempIndex = ((gun_index==2) ? 1: 0);
  3785. }
  3786. else
  3787. {
  3788. tempIndex = gun_index;
  3789. }
  3790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3793. {
  3794. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3795. }
  3796. } // END OF FOR CHAdeMO_QUANTITY
  3797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3798. }
  3799. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3800. {
  3801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3802. {
  3803. tempIndex = ((gun_index==2) ? 1: 0);
  3804. }
  3805. else
  3806. {
  3807. tempIndex = gun_index;
  3808. }
  3809. for (int index = 0; index < CCS_QUANTITY; index++)
  3810. {
  3811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3812. {
  3813. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3814. }
  3815. } // END OF FOR CCS_QUANTITY
  3816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3817. }
  3818. else if(gunType[gun_index] == 'G')
  3819. {
  3820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3821. {
  3822. tempIndex = ((gun_index==2) ? 1: 0);
  3823. }
  3824. else
  3825. {
  3826. tempIndex = gun_index;
  3827. }
  3828. for (int index = 0; index < GB_QUANTITY; index++)
  3829. {
  3830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3831. {
  3832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3833. }
  3834. } // END OF FOR GB_QUANTITY
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3836. }
  3837. else if(gunType[gun_index] == 'O')
  3838. {
  3839. tempIndex = gun_index;
  3840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3841. {
  3842. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3843. {
  3844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3845. }
  3846. }
  3847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3848. }
  3849. else
  3850. {
  3851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3852. {
  3853. tempIndex = 2;
  3854. }
  3855. else
  3856. {
  3857. tempIndex = gun_index;
  3858. }
  3859. for (int index = 0; index < AC_QUANTITY; index++)
  3860. {
  3861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3862. {
  3863. 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
  3864. }
  3865. } // END OF FOR AC_QUANTITY
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3867. }
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3873. //====================== SoC ================================
  3874. //idx_sample=5;
  3875. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3876. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3877. {
  3878. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3879. {
  3880. tempIndex = ((gun_index==2) ? 1: 0);
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. if(gunType[gun_index] == 'J')
  3887. {
  3888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3889. {
  3890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3891. {
  3892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3893. }
  3894. }
  3895. }
  3896. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3897. {
  3898. for (int index = 0; index < CCS_QUANTITY; index++)
  3899. {
  3900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3901. {
  3902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3903. }
  3904. }
  3905. }
  3906. else if(gunType[gun_index] == 'G')
  3907. {
  3908. for (int index = 0; index < GB_QUANTITY; index++)
  3909. {
  3910. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3911. {
  3912. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3913. }
  3914. }
  3915. }
  3916. else if(gunType[gun_index] == 'O')
  3917. {
  3918. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3919. {
  3920. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3921. {
  3922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  3923. }
  3924. }
  3925. }
  3926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3932. } // END FOR DC CASE
  3933. // ================================= Current.Import L2 ===============================================
  3934. //idx_sample=6;
  3935. // AC 3 phse L2 current
  3936. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3937. {
  3938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3939. {
  3940. tempIndex = 2;
  3941. }
  3942. else
  3943. {
  3944. tempIndex = gun_index;
  3945. }
  3946. for (int index = 0; index < AC_QUANTITY; index++)
  3947. {
  3948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3949. {
  3950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3951. }
  3952. }// End of for AC_QUANTITY
  3953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3954. }
  3955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3960. // ================================= Current.Import L3 ===============================================
  3961. //idx_sample=7;
  3962. // AC 3 phse L3 current
  3963. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3964. {
  3965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3966. {
  3967. tempIndex = 2;
  3968. }
  3969. else
  3970. {
  3971. tempIndex = gun_index;
  3972. }
  3973. for (int index = 0; index < AC_QUANTITY; index++)
  3974. {
  3975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3976. {
  3977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3978. }
  3979. }// End of for AC_QUANTITY
  3980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3981. }
  3982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3987. //============================ Voltage L2 ====================================
  3988. //idx_sample=8;
  3989. // AC 3 phse L2 voltage
  3990. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3991. {
  3992. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3993. {
  3994. tempIndex = 2;
  3995. }
  3996. else
  3997. {
  3998. tempIndex = gun_index;
  3999. }
  4000. for (int index = 0; index < AC_QUANTITY; index++)
  4001. {
  4002. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4003. {
  4004. 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
  4005. }
  4006. } // END OF FOR AC_QUANTITY
  4007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4008. }
  4009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4014. //============================ Voltage L3 ====================================
  4015. //idx_sample=8;
  4016. // AC 3 phse L3 voltage
  4017. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4018. {
  4019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4020. {
  4021. tempIndex = 2;
  4022. }
  4023. else
  4024. {
  4025. tempIndex = gun_index;
  4026. }
  4027. for (int index = 0; index < AC_QUANTITY; index++)
  4028. {
  4029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4030. {
  4031. 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
  4032. }
  4033. } // END OF FOR AC_QUANTITY
  4034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4035. }
  4036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4041. //================================================ Message create ====================================================
  4042. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4043. {
  4044. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4045. ,gun_index+1
  4046. ,MESSAGE_TYPE_CALL
  4047. ,guid
  4048. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4049. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4050. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4052. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4053. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  4090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  4091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  4092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  4093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  4094. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  4095. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  4096. );
  4097. }
  4098. else
  4099. {
  4100. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  4101. {
  4102. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4103. ,gun_index+1
  4104. ,MESSAGE_TYPE_CALL
  4105. ,guid
  4106. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4107. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4108. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4109. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4110. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4111. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4112. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4113. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4114. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4115. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4116. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4118. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4119. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4147. );
  4148. }
  4149. else
  4150. {
  4151. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4152. ,gun_index+1
  4153. ,MESSAGE_TYPE_CALL
  4154. ,guid
  4155. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4156. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4157. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4158. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4159. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4160. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4161. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4162. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4169. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4170. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4171. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4172. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4173. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4174. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4175. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4176. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4177. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4178. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4180. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4181. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4205. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4206. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4207. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4208. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4209. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4210. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4211. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4213. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4214. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4215. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4216. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4217. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4218. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4219. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4220. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4221. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4222. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4223. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4224. );
  4225. }
  4226. }
  4227. #if 1 // for TempStopTransaction
  4228. //Delete TempStopTransaction
  4229. if((access(TempStopTransaction,F_OK))!=-1)
  4230. {
  4231. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4232. }
  4233. #endif
  4234. #if 1
  4235. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4236. if(hashmap_operation(0, guid, tempdata) == 1)
  4237. {
  4238. result = PASS;
  4239. DEBUG_INFO("StopTransaction mapitem pass\n");
  4240. }
  4241. #endif
  4242. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4243. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4244. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4245. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4246. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4247. {
  4248. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4249. }
  4250. //for test
  4251. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4252. return result;
  4253. }
  4254. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4255. {
  4256. mtrace();
  4257. int result = FAIL;
  4258. char guid[37]={0};
  4259. char tempdata[65]={0};
  4260. int tempIndex = 0;
  4261. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4262. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4263. //set value
  4264. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4265. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4266. random_uuid(guid);
  4267. //UTC Date time
  4268. struct timeval tmnow;
  4269. struct tm *tm;
  4270. char buf[28];//, usec_buf[6];
  4271. gettimeofday(&tmnow, NULL);
  4272. time_t t;
  4273. t = time(NULL);
  4274. /*UTC time and date*/
  4275. tm = gmtime(&t);
  4276. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4278. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4279. //idx_sample=0;
  4280. //********************************(1)Current.Import L1************************************************/
  4281. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4282. if(gunType[gun_index] == 'J')
  4283. {
  4284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4285. {
  4286. tempIndex = ((gun_index==2) ? 1: 0);
  4287. }
  4288. else
  4289. {
  4290. tempIndex = gun_index;
  4291. }
  4292. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4293. {
  4294. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4295. {
  4296. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4297. }
  4298. }
  4299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4300. }
  4301. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4302. {
  4303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4304. {
  4305. tempIndex = ((gun_index==2) ? 1: 0);
  4306. }
  4307. else
  4308. {
  4309. tempIndex = gun_index;
  4310. }
  4311. for (int index = 0; index < CCS_QUANTITY; index++)
  4312. {
  4313. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4314. {
  4315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4316. }
  4317. }
  4318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4319. }
  4320. else if(gunType[gun_index] == 'G')
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4323. {
  4324. tempIndex = ((gun_index==2) ? 1: 0);
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < GB_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4333. {
  4334. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4335. }
  4336. }
  4337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4338. }
  4339. else if(gunType[gun_index] == 'O')
  4340. {
  4341. tempIndex = gun_index;
  4342. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4343. {
  4344. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4345. {
  4346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4347. }
  4348. }
  4349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4350. }
  4351. else
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4354. {
  4355. tempIndex = 2;
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < AC_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4364. {
  4365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4366. }
  4367. }
  4368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4369. }
  4370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4375. //idx_sample=1;
  4376. //********************************(2)Energy.Active.Import.Register ************************************************/
  4377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4378. if(gunType[gun_index] == 'J')
  4379. {
  4380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4381. {
  4382. tempIndex = ((gun_index==2) ? 1: 0);
  4383. }
  4384. else
  4385. {
  4386. tempIndex = gun_index;
  4387. }
  4388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4389. {
  4390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4391. {
  4392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4393. }
  4394. }
  4395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4396. }
  4397. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4398. {
  4399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4400. {
  4401. tempIndex = ((gun_index==2) ? 1: 0);
  4402. }
  4403. else
  4404. {
  4405. tempIndex = gun_index;
  4406. }
  4407. for (int index = 0; index < CCS_QUANTITY; index++)
  4408. {
  4409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4410. {
  4411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4412. }
  4413. }
  4414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4415. }
  4416. else if(gunType[gun_index] == 'G')
  4417. {
  4418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4419. {
  4420. tempIndex = ((gun_index==2) ? 1: 0);
  4421. }
  4422. else
  4423. {
  4424. tempIndex = gun_index;
  4425. }
  4426. for (int index = 0; index < GB_QUANTITY; index++)
  4427. {
  4428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4429. {
  4430. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4431. }
  4432. }
  4433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4434. }
  4435. else if(gunType[gun_index] == 'O')
  4436. {
  4437. tempIndex = gun_index;
  4438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4443. }
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4446. }
  4447. else
  4448. {
  4449. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4450. {
  4451. tempIndex = 2;
  4452. }
  4453. else
  4454. {
  4455. tempIndex = gun_index;
  4456. }
  4457. for (int index = 0; index < AC_QUANTITY; index++)
  4458. {
  4459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4460. {
  4461. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4462. }
  4463. }
  4464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4465. }
  4466. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4471. //idx_sample=2;
  4472. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4473. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4474. if(gunType[gun_index] == 'J')
  4475. {
  4476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4477. {
  4478. tempIndex = ((gun_index==2) ? 1: 0);
  4479. }
  4480. else
  4481. {
  4482. tempIndex = gun_index;
  4483. }
  4484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4485. {
  4486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4487. {
  4488. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4489. }
  4490. } // END OF FOR CHAdeMO_QUANTITY
  4491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4492. }
  4493. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4494. {
  4495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4496. {
  4497. tempIndex = ((gun_index==2) ? 1: 0);
  4498. }
  4499. else
  4500. {
  4501. tempIndex = gun_index;
  4502. }
  4503. for (int index = 0; index < CCS_QUANTITY; index++)
  4504. {
  4505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4506. {
  4507. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4508. }
  4509. } // END OF CCS_QUANTITY
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4511. }
  4512. else if(gunType[gun_index] == 'G')
  4513. {
  4514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4515. {
  4516. tempIndex = ((gun_index==2) ? 1: 0);
  4517. }
  4518. else
  4519. {
  4520. tempIndex = gun_index;
  4521. }
  4522. for (int index = 0; index < GB_QUANTITY; index++)
  4523. {
  4524. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4525. {
  4526. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4527. }
  4528. } // END OF GB_QUANTITY
  4529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4530. }
  4531. else if(gunType[gun_index] == 'O')
  4532. {
  4533. tempIndex = gun_index;
  4534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4535. {
  4536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4537. {
  4538. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4539. }
  4540. }
  4541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4542. }
  4543. else
  4544. {
  4545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4546. {
  4547. tempIndex = 2;
  4548. }
  4549. else
  4550. {
  4551. tempIndex = gun_index;
  4552. }
  4553. for (int index = 0; index < AC_QUANTITY; index++)
  4554. {
  4555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4556. {
  4557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4558. }
  4559. }
  4560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4561. }
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4567. //idx_sample=3;
  4568. //********************************(4)Power.Active.Import************************************************/
  4569. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4570. if(gunType[gun_index] == 'J')
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4573. {
  4574. tempIndex = ((gun_index==2) ? 1: 0);
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4581. {
  4582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4583. {
  4584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4585. }
  4586. } // END OF FOR
  4587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4588. }
  4589. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4590. {
  4591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4592. {
  4593. tempIndex = ((gun_index==2) ? 1: 0);
  4594. }
  4595. else
  4596. {
  4597. tempIndex = gun_index;
  4598. }
  4599. for (int index = 0; index < CCS_QUANTITY; index++)
  4600. {
  4601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4602. {
  4603. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4604. }
  4605. }
  4606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4607. }
  4608. else if(gunType[gun_index] == 'G')
  4609. {
  4610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4611. {
  4612. tempIndex = ((gun_index==2) ? 1: 0);
  4613. }
  4614. else
  4615. {
  4616. tempIndex = gun_index;
  4617. }
  4618. for (int index = 0; index < GB_QUANTITY; index++)
  4619. {
  4620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4621. {
  4622. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4623. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4624. }
  4625. }
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4627. }
  4628. else if(gunType[gun_index] == 'O')
  4629. {
  4630. tempIndex = gun_index;
  4631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4632. {
  4633. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4634. {
  4635. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4637. }
  4638. }
  4639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4640. }
  4641. else
  4642. {
  4643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4644. {
  4645. tempIndex = 2;
  4646. }
  4647. else
  4648. {
  4649. tempIndex = gun_index;
  4650. }
  4651. for (int index = 0; index < AC_QUANTITY; index++)
  4652. {
  4653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4654. {
  4655. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4656. }
  4657. }
  4658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4659. }
  4660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4665. //idx_sample=4;
  4666. //***********************************************(5)VOLTAGE L1******************************************************/
  4667. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4668. if(gunType[gun_index] == 'J')
  4669. {
  4670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4671. {
  4672. tempIndex = ((gun_index==2) ? 1: 0);
  4673. }
  4674. else
  4675. {
  4676. tempIndex = gun_index;
  4677. }
  4678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4679. {
  4680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4681. {
  4682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4683. }
  4684. }
  4685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4686. }
  4687. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4688. {
  4689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4690. {
  4691. tempIndex = ((gun_index==2) ? 1: 0);
  4692. }
  4693. else
  4694. {
  4695. tempIndex = gun_index;
  4696. }
  4697. for (int index = 0; index < CCS_QUANTITY; index++)
  4698. {
  4699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4700. {
  4701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4702. }
  4703. }
  4704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4705. }
  4706. else if(gunType[gun_index] == 'G')
  4707. {
  4708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4709. {
  4710. tempIndex = ((gun_index==2) ? 1: 0);
  4711. }
  4712. else
  4713. {
  4714. tempIndex = gun_index;
  4715. }
  4716. for (int index = 0; index < GB_QUANTITY; index++)
  4717. {
  4718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4719. {
  4720. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4721. }
  4722. }
  4723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4724. }
  4725. else if(gunType[gun_index] == 'O')
  4726. {
  4727. tempIndex = gun_index;
  4728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4729. {
  4730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4731. {
  4732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4733. }
  4734. }
  4735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4736. }
  4737. else
  4738. {
  4739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4740. {
  4741. tempIndex = 2;
  4742. }
  4743. else
  4744. {
  4745. tempIndex = gun_index;
  4746. }
  4747. for (int index = 0; index < AC_QUANTITY; index++)
  4748. {
  4749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4750. {
  4751. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4752. }
  4753. }
  4754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4755. }
  4756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4761. //***********************************************(6)SOC******************************************************/
  4762. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4763. {
  4764. //idx_sample=5;
  4765. //sampledValue = NULL;
  4766. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4767. {
  4768. tempIndex = ((gun_index==2) ? 1: 0);
  4769. }
  4770. else
  4771. {
  4772. tempIndex = gun_index;
  4773. }
  4774. if(gunType[gun_index] == 'J')
  4775. {
  4776. //tempIndex = ((gun_index==2) ? 1: 0);
  4777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4778. {
  4779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4780. {
  4781. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4782. }
  4783. }
  4784. }
  4785. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4786. {
  4787. //tempIndex = ((gun_index==2) ? 1: 0);
  4788. for (int index = 0; index < CCS_QUANTITY; index++)
  4789. {
  4790. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4791. {
  4792. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4793. }
  4794. }
  4795. }
  4796. else if(gunType[gun_index] == 'G')
  4797. {
  4798. //tempIndex = ((gun_index==2) ? 1: 0);
  4799. for (int index = 0; index < GB_QUANTITY; index++)
  4800. {
  4801. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4802. {
  4803. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4804. }
  4805. }
  4806. }
  4807. else if(gunType[gun_index] == 'O')
  4808. {
  4809. //tempIndex = ((gun_index==2) ? 1: 0);
  4810. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4811. {
  4812. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4813. {
  4814. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4815. }
  4816. }
  4817. }
  4818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4824. }
  4825. //********************************(7)Current.Import L2************************************************/
  4826. // Only for AC 3 phase
  4827. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4828. {
  4829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4830. {
  4831. tempIndex = 2;
  4832. }
  4833. else
  4834. {
  4835. tempIndex = gun_index;
  4836. }
  4837. for (int index = 0; index < AC_QUANTITY; index++)
  4838. {
  4839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4840. {
  4841. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4842. }
  4843. }
  4844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4845. }
  4846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4851. //********************************(8)Current.Import L3************************************************/
  4852. // Only for AC 3 phase
  4853. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4854. {
  4855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4856. {
  4857. tempIndex = 2;
  4858. }
  4859. else
  4860. {
  4861. tempIndex = gun_index;
  4862. }
  4863. for (int index = 0; index < AC_QUANTITY; index++)
  4864. {
  4865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4866. {
  4867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4868. }
  4869. }
  4870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4871. }
  4872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4877. //***********************************************(9)VOLTAGE L2******************************************************/
  4878. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4879. {
  4880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4881. {
  4882. tempIndex = 2;
  4883. }
  4884. else
  4885. {
  4886. tempIndex = gun_index;
  4887. }
  4888. for (int index = 0; index < AC_QUANTITY; index++)
  4889. {
  4890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4891. {
  4892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4893. }
  4894. }
  4895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4896. }
  4897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4902. //***********************************************(10)VOLTAGE L3******************************************************/
  4903. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4904. {
  4905. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4906. {
  4907. tempIndex = 2;
  4908. }
  4909. else
  4910. {
  4911. tempIndex = gun_index;
  4912. }
  4913. for (int index = 0; index < AC_QUANTITY; index++)
  4914. {
  4915. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4916. {
  4917. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4918. }
  4919. }
  4920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4921. }
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4927. // Message create ====================================================================================================
  4928. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4929. {
  4930. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4931. ,gun_index + 1
  4932. ,MESSAGE_TYPE_CALL
  4933. ,guid
  4934. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4935. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4936. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4937. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4938. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4939. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4940. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4941. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4942. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4943. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4944. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4945. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4946. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4947. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4948. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4949. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4950. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4951. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4952. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4953. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4954. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4955. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4956. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4957. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4958. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4959. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4960. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4961. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4962. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4963. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4964. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4965. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4966. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4967. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4968. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4969. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4970. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4971. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4972. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4973. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4974. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4975. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4976. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4977. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4978. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4979. );
  4980. }
  4981. else
  4982. {
  4983. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4984. {
  4985. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4986. ,gun_index + 1
  4987. ,MESSAGE_TYPE_CALL
  4988. ,guid
  4989. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4990. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4991. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4992. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4993. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4994. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4995. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4996. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4997. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4998. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4999. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  5000. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  5001. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  5002. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  5003. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  5004. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  5005. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  5006. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  5007. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  5008. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  5009. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  5010. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  5011. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  5012. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  5013. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  5014. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  5015. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  5016. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  5017. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  5018. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  5019. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  5020. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  5021. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  5022. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  5023. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  5024. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  5025. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  5026. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  5027. );
  5028. }
  5029. else
  5030. {
  5031. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  5032. ,gun_index + 1
  5033. ,MESSAGE_TYPE_CALL
  5034. ,guid
  5035. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  5036. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  5037. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  5038. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  5039. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  5040. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  5041. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  5042. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  5043. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  5044. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  5045. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  5046. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  5047. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  5048. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  5049. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  5050. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  5051. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  5052. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  5053. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  5054. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  5055. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  5056. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  5057. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  5058. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  5059. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  5060. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  5061. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  5062. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  5063. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  5064. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  5065. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  5066. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  5067. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  5068. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  5069. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  5070. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  5071. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  5072. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  5073. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  5074. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  5075. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  5076. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  5077. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  5078. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  5079. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  5080. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  5081. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  5082. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  5083. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  5084. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  5085. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  5086. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  5087. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  5088. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  5089. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  5090. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  5091. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  5092. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  5093. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  5094. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  5095. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  5096. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  5097. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  5098. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  5099. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  5100. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  5101. );
  5102. }
  5103. }
  5104. // Put request guid to hash map
  5105. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5106. 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*/)
  5107. {
  5108. result = PASS;
  5109. DEBUG_INFO("MeterValues mapitem pass\n");
  5110. }
  5111. if(dataType != ReadingContext_Trigger)
  5112. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5113. else
  5114. LWS_Send(queuedata +2);
  5115. return result;
  5116. }
  5117. //==========================================
  5118. // send confirm routine
  5119. //==========================================
  5120. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5121. {
  5122. mtrace();
  5123. int result = FAIL;
  5124. char message[100]={0};
  5125. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5126. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5127. LWS_Send(message);
  5128. result = TRUE;
  5129. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5130. return result;
  5131. }
  5132. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5133. {
  5134. mtrace();
  5135. int result = FAIL;
  5136. char message[100]={0};
  5137. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5139. LWS_Send(message);
  5140. result = TRUE;
  5141. return result;
  5142. }
  5143. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5144. {
  5145. mtrace();
  5146. int result = FAIL;
  5147. char message[100]={0};
  5148. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5149. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5150. LWS_Send(message);
  5151. result = TRUE;
  5152. return result;
  5153. }
  5154. int sendClearCacheConfirmation(char *uuid,char *payload)
  5155. {
  5156. mtrace();
  5157. int result = FAIL;
  5158. char message[500]={0};
  5159. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5160. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5161. LWS_Send(message);
  5162. return result;
  5163. }
  5164. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5165. {
  5166. mtrace();
  5167. int result = FAIL;
  5168. char message[500]={0};
  5169. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5170. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5171. LWS_Send(message);
  5172. return result;
  5173. }
  5174. int sendDataTransferConfirmation(char *uuid,char *payload)
  5175. {
  5176. mtrace();
  5177. char statusStr[20]={0};
  5178. char dataStr[10]={0};
  5179. char sstr[20]={0};
  5180. int c = 0;
  5181. char *loc;
  5182. int result = FAIL;
  5183. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5184. /**********************status**************************/
  5185. loc = strstr(payload, "status");
  5186. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5187. c = 0;
  5188. while (loc[3+strlen("status")+c] != '\"')
  5189. {
  5190. sstr[c] = loc[3+strlen("status")+c];
  5191. c++;
  5192. }
  5193. sstr[c] = '\0';
  5194. strcpy(statusStr, sstr);
  5195. /**********************data**************************/
  5196. loc = strstr(payload, "data");
  5197. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5198. c = 0;
  5199. while (loc[3+strlen("data")+c] != '\"')
  5200. {
  5201. sstr[c] = loc[3+strlen("data")+c];
  5202. c++;
  5203. }
  5204. sstr[c] = '\0';
  5205. strcpy(dataStr, sstr);
  5206. return result;
  5207. }
  5208. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5209. {
  5210. mtrace();
  5211. int result = FAIL;
  5212. char message[1000]={0};
  5213. int CompositeScheduleIndex = 0;
  5214. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5215. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5216. if(nPeriod == 0)
  5217. {
  5218. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5219. {
  5220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5221. ,MESSAGE_TYPE_CALLRESULT
  5222. ,uuid
  5223. ,payload
  5224. ,connectorIdInt);
  5225. }
  5226. else
  5227. {
  5228. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5229. ,MESSAGE_TYPE_CALLRESULT
  5230. ,uuid
  5231. ,payload
  5232. ,connectorIdInt
  5233. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5234. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5235. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5236. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5237. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5238. }
  5239. }
  5240. else
  5241. {
  5242. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5243. ,MESSAGE_TYPE_CALLRESULT
  5244. ,uuid
  5245. ,payload
  5246. ,connectorIdInt
  5247. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5248. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5249. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5250. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5251. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5252. {
  5253. if (idx_sample == 0)
  5254. {
  5255. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5256. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5257. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5258. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5259. }
  5260. else
  5261. {
  5262. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5263. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5264. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5265. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5266. }
  5267. }
  5268. sprintf(message + strlen(message), "]}}]");
  5269. }
  5270. LWS_Send(message);
  5271. result = TRUE;
  5272. return result;
  5273. }
  5274. int sendGetConfigurationConfirmation(char *uuid)
  5275. {
  5276. mtrace();
  5277. int result = FAIL;
  5278. int MaxKeySupported = 0;
  5279. int sentConfigurationNumber= 0;
  5280. int sentunConfigurationNumber= 0;
  5281. char message[4000]={0};
  5282. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5283. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5284. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5285. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5286. ,MESSAGE_TYPE_CALLRESULT
  5287. ,uuid );
  5288. //configuration key
  5289. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5290. {
  5291. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5292. {
  5293. if (sentConfigurationNumber == 0)
  5294. {
  5295. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5296. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5297. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5298. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5299. }
  5300. else
  5301. {
  5302. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5303. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5304. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5305. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5306. }
  5307. sentConfigurationNumber = sentConfigurationNumber + 1;
  5308. }
  5309. }
  5310. sprintf(message + strlen(message), "]");
  5311. if(UnknownKeynum != 0)
  5312. {
  5313. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5314. //unkown key
  5315. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5316. {
  5317. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5318. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5319. if(sentunConfigurationNumber == 0)
  5320. {
  5321. sprintf(message + strlen(message), "\"%s\""
  5322. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5323. }
  5324. else
  5325. {
  5326. sprintf(message + strlen(message), ",\"%s\""
  5327. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5328. }
  5329. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5330. }
  5331. sprintf(message + strlen(message), "]");
  5332. }
  5333. sprintf(message + strlen(message), "}]");
  5334. LWS_Send(message);
  5335. return result;
  5336. }
  5337. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5338. {
  5339. mtrace();
  5340. int result = FAIL;
  5341. char message[400]={0};
  5342. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5343. if(strcmp(payload,"")==0)
  5344. {
  5345. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5346. }
  5347. else
  5348. {
  5349. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5350. }
  5351. LWS_Send(message);
  5352. result = TRUE;
  5353. return result;
  5354. }
  5355. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5356. {
  5357. mtrace();
  5358. int result = FAIL;
  5359. char message[80]={0};
  5360. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5361. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5362. LWS_Send(message);
  5363. result = TRUE;
  5364. return result;
  5365. }
  5366. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5367. {
  5368. mtrace();
  5369. int result = FAIL;
  5370. char message[80]={0};
  5371. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5372. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5373. LWS_Send(message);
  5374. result = TRUE;
  5375. return result;
  5376. }
  5377. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5378. {
  5379. mtrace();
  5380. int result = FAIL;
  5381. char message[80]={0};
  5382. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5383. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5384. LWS_Send(message);
  5385. result = TRUE;
  5386. return result;
  5387. }
  5388. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5389. {
  5390. mtrace();
  5391. int result = FAIL;
  5392. char message[80]={0};
  5393. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5394. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5395. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5396. LWS_Send(message);
  5397. result = TRUE;
  5398. return result;
  5399. }
  5400. int sendResetConfirmation(char *uuid,char *payload)
  5401. {
  5402. mtrace();
  5403. int result = FAIL;
  5404. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5405. char message[80]={0};
  5406. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5407. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5408. LWS_Send(message);
  5409. result = TRUE;
  5410. return result;
  5411. }
  5412. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5413. {
  5414. mtrace();
  5415. int result = FAIL;
  5416. char message[500]={0};
  5417. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5418. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5419. LWS_Send(message);
  5420. result = TRUE;
  5421. return result;
  5422. }
  5423. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5424. {
  5425. mtrace();
  5426. int result = FAIL;
  5427. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5428. char message[80]={0};
  5429. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5430. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5431. LWS_Send(message);
  5432. result = TRUE;
  5433. return result;
  5434. }
  5435. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5436. {
  5437. mtrace();
  5438. int result = FAIL;
  5439. char message[80]={0};
  5440. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5441. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5442. LWS_Send(message);
  5443. result = TRUE;
  5444. return result;
  5445. }
  5446. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5447. {
  5448. mtrace();
  5449. int result = FAIL;
  5450. char message[80]={0};
  5451. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5452. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5453. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5454. LWS_Send(message);
  5455. result = TRUE;
  5456. return result;
  5457. }
  5458. int sendUpdateFirmwareConfirmation(char *uuid)
  5459. {
  5460. mtrace();
  5461. int result = FAIL;
  5462. char message[60]={0};
  5463. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5464. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5465. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5466. LWS_Send(message);
  5467. result = TRUE;
  5468. return result;
  5469. }
  5470. //==========================================
  5471. // send CallError routine
  5472. //==========================================
  5473. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5474. {
  5475. mtrace();
  5476. char message[220]={0};
  5477. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5478. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5479. LWS_Send(message);
  5480. }
  5481. //==========================================
  5482. // Handle server request routine Start
  5483. //==========================================
  5484. int handleCancelReservationRequest(char *uuid, char *payload)
  5485. {
  5486. mtrace();
  5487. int result = FAIL;
  5488. int gunNO = 0;
  5489. int reservationIdInt = -1;
  5490. char comfirmstr[20];
  5491. DEBUG_INFO("handleCancelReservationRequest...\n");
  5492. json_object *CancelReservation;
  5493. CancelReservation = json_tokener_parse(payload);
  5494. if(!is_error(CancelReservation))
  5495. {
  5496. // Required data
  5497. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5498. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5499. }
  5500. json_object_put(CancelReservation);
  5501. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5502. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5503. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5504. if(reservationIdInt != -1)
  5505. {
  5506. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5507. //check Transaction active
  5508. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5512. {
  5513. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5514. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5515. if(gunType[2] == 'J')
  5516. {
  5517. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5518. }
  5519. else
  5520. {
  5521. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5522. }
  5523. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5524. goto end;
  5525. }
  5526. }
  5527. for (int index = 0; index < CCS_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5530. {
  5531. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5532. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5533. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5534. {
  5535. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5536. }
  5537. else
  5538. {
  5539. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5540. }
  5541. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5542. goto end;
  5543. }
  5544. }
  5545. for (int index = 0; index < GB_QUANTITY; index++)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5548. {
  5549. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5550. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5551. if(gunType[2] == 'G')
  5552. {
  5553. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5554. }
  5555. else
  5556. {
  5557. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5558. }
  5559. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5560. goto end;
  5561. }
  5562. }
  5563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5564. {
  5565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5566. {
  5567. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5568. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5569. if(gunType[2] == 'G')
  5570. {
  5571. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5572. }
  5573. else
  5574. {
  5575. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5576. }
  5577. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5578. goto end;
  5579. }
  5580. }
  5581. for (int index = 0; index < AC_QUANTITY; index++)
  5582. {
  5583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5584. {
  5585. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5586. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5588. {
  5589. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5590. }
  5591. else
  5592. {
  5593. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5594. }
  5595. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5596. goto end;
  5597. }
  5598. }
  5599. }
  5600. //The reservationId does NOT match the reservationId
  5601. sendCancelReservationConfirmation(uuid, comfirmstr);
  5602. end:
  5603. // Fill in ocpp packet uuid
  5604. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5605. return result;
  5606. }
  5607. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5608. {
  5609. mtrace();
  5610. int result = FAIL;
  5611. int gunIndex = 0;
  5612. char typeStr[16]={0};
  5613. char comfirmstr[20];
  5614. int specificId = FALSE;
  5615. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5616. json_object *ChangeAvailability;
  5617. ChangeAvailability = json_tokener_parse(payload);
  5618. if(!is_error(ChangeAvailability))
  5619. {
  5620. // Required data
  5621. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5622. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5623. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5624. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5625. }
  5626. json_object_put(ChangeAvailability);
  5627. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5628. {
  5629. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5630. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5631. }
  5632. else if(gunIndex == 0)
  5633. {
  5634. for(int i=0; i < gunTotalNumber; i++)
  5635. {
  5636. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5637. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5638. }
  5639. }
  5640. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5642. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5643. {
  5644. specificId = TRUE;
  5645. }
  5646. if(specificId == FALSE)
  5647. goto end;
  5648. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5649. {
  5650. //----------------------gunIndex is 0 ------------------------------------------------//
  5651. if(gunIndex == 0)
  5652. {
  5653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5654. {
  5655. for(int i=0; i < gunTotalNumber; i++)
  5656. {
  5657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5658. {
  5659. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5660. {
  5661. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5664. goto end;
  5665. }
  5666. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5667. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5668. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5670. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5671. {
  5672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5673. goto end;
  5674. }
  5675. }
  5676. }//END FOR CHAdeMO_QUANTITY
  5677. for (int index = 0; index < CCS_QUANTITY; index++)
  5678. {
  5679. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5680. {
  5681. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5682. {
  5683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5684. goto end;
  5685. }
  5686. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5687. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5688. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5689. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5690. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5691. {
  5692. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5693. goto end;
  5694. }
  5695. }
  5696. }//END FOR CCS_QUANTITY
  5697. for (int index = 0; index < GB_QUANTITY; index++)
  5698. {
  5699. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5700. {
  5701. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5702. {
  5703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5704. goto end;
  5705. }
  5706. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5707. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5708. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5709. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5710. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5711. {
  5712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5713. goto end;
  5714. }
  5715. }
  5716. }// END FOR GB_QUANTITY
  5717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5718. {
  5719. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5720. {
  5721. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5722. {
  5723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5724. goto end;
  5725. }
  5726. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5728. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5729. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5730. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5731. {
  5732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5733. goto end;
  5734. }
  5735. }
  5736. }// END FOR GENERAL_GUN_QUANTITY
  5737. for (int index = 0; index < AC_QUANTITY; index++)
  5738. {
  5739. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5740. {
  5741. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5742. {
  5743. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5744. goto end;
  5745. }
  5746. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5747. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5748. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5749. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5750. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5751. {
  5752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5753. goto end;
  5754. }
  5755. }
  5756. }//END FOR AC_QUANTITY
  5757. }// END FOR gunTotalNumber
  5758. }
  5759. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5760. {
  5761. for(int i=0; i < gunTotalNumber; i++)
  5762. {
  5763. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5764. {
  5765. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5766. goto end;
  5767. }
  5768. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5769. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5770. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5771. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5773. {
  5774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5775. goto end;
  5776. }
  5777. }
  5778. }
  5779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5780. goto end;
  5781. }
  5782. //----------------------gunIndex is not 0 ------------------------------------------------//
  5783. //check Transaction active
  5784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5785. {
  5786. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5787. {
  5788. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5789. {
  5790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5791. goto end;
  5792. }
  5793. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5794. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5795. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5796. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5797. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5798. {
  5799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5800. goto end;
  5801. }
  5802. else
  5803. {
  5804. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5806. goto end;
  5807. }
  5808. }
  5809. }//END FOR CHAdeMO_QUANTITY
  5810. for (int index = 0; index < CCS_QUANTITY; index++)
  5811. {
  5812. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5813. {
  5814. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5815. {
  5816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5817. goto end;
  5818. }
  5819. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5820. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5821. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5822. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5823. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5824. {
  5825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5826. goto end;
  5827. }
  5828. else
  5829. {
  5830. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5832. goto end;
  5833. }
  5834. }
  5835. }//END FOR CCS_QUANTITY
  5836. for (int index = 0; index < GB_QUANTITY; index++)
  5837. {
  5838. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5839. {
  5840. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5841. {
  5842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5843. goto end;
  5844. }
  5845. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5846. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5847. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5848. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5849. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5850. {
  5851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5852. goto end;
  5853. }
  5854. else
  5855. {
  5856. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5858. goto end;
  5859. }
  5860. }
  5861. }// END FOR GB_QUANTITY
  5862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5863. {
  5864. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5865. {
  5866. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5867. {
  5868. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5869. goto end;
  5870. }
  5871. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5872. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5873. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5874. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5875. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5876. {
  5877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5878. goto end;
  5879. }
  5880. else
  5881. {
  5882. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5884. goto end;
  5885. }
  5886. }
  5887. }// END FOR GENERAL_GUN_QUANTITY
  5888. for (int index = 0; index < AC_QUANTITY; index++)
  5889. {
  5890. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5891. {
  5892. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5893. {
  5894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5895. goto end;
  5896. }
  5897. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5898. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5899. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5900. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5901. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5902. {
  5903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5904. goto end;
  5905. }
  5906. else
  5907. {
  5908. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5909. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5910. goto end;
  5911. }
  5912. }
  5913. }//END FOR AC_QUANTITY
  5914. }//END FOR AvailabilityTypeStr[Inoperative]
  5915. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5916. {
  5917. //----------------------gunIndex is 0 ------------------------------------------------//
  5918. if(gunIndex == 0)
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5921. {
  5922. for(int i=0; i < gunTotalNumber; i++)
  5923. {
  5924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5925. {
  5926. 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
  5927. {
  5928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5929. goto end;
  5930. }
  5931. }//END FOR CHAdeMO_QUANTITY
  5932. for (int index = 0; index < CCS_QUANTITY; index++)
  5933. {
  5934. 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
  5935. {
  5936. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5937. goto end;
  5938. }
  5939. }//END FOR CCS_QUANTITY
  5940. for (int index = 0; index < GB_QUANTITY; index++)
  5941. {
  5942. 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
  5943. {
  5944. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5946. goto end;
  5947. }
  5948. }// END FOR GB_QUANTITY
  5949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5950. {
  5951. if ((gunType[i] == 'G')&&(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] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5952. {
  5953. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5955. goto end;
  5956. }
  5957. }// END FOR GENERAL_GUN_QUANTITY
  5958. for (int index = 0; index < AC_QUANTITY; index++)
  5959. {
  5960. 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
  5961. {
  5962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5963. goto end;
  5964. }
  5965. }//END FOR CHAdeMO_QUANTITY
  5966. }// END FOR gunTotalNumber
  5967. }
  5968. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5969. {
  5970. for(int i=0; i < gunTotalNumber; i++)
  5971. {
  5972. for (int index = 0; index < AC_QUANTITY; index++)
  5973. {
  5974. 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
  5975. {
  5976. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5977. goto end;
  5978. }
  5979. }//END FOR CHAdeMO_QUANTITY
  5980. } // END FOR gunTotalNumber
  5981. }
  5982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5983. goto end;
  5984. }
  5985. //----------------------gunIndex is not 0 ------------------------------------------------//
  5986. //check Transaction active
  5987. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5988. {
  5989. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5990. {
  5991. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5992. goto end;
  5993. }
  5994. }//END FOR CHAdeMO_QUANTITY
  5995. for (int index = 0; index < CCS_QUANTITY; index++)
  5996. {
  5997. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5998. {
  5999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6000. goto end;
  6001. }
  6002. }//END FOR CCS_QUANTITY
  6003. for (int index = 0; index < GB_QUANTITY; index++)
  6004. {
  6005. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6006. {
  6007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6008. goto end;
  6009. }
  6010. }// END FOR GB_QUANTITY
  6011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6012. {
  6013. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6014. {
  6015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6016. goto end;
  6017. }
  6018. }// END FOR GENERAL_GUN_QUANTITY
  6019. for (int index = 0; index < AC_QUANTITY; index++)
  6020. {
  6021. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6022. {
  6023. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6024. goto end;
  6025. }
  6026. }//END FOR AC_QUANTITY
  6027. }//END FOR AvailabilityTypeStr[Operative]
  6028. end:
  6029. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6030. {
  6031. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6032. }
  6033. else
  6034. {
  6035. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6036. }
  6037. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6038. {
  6039. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6040. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6041. }
  6042. else if(gunIndex == 0)
  6043. {
  6044. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6045. {
  6046. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6047. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6048. }
  6049. }
  6050. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6051. return result;
  6052. }
  6053. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6054. {
  6055. mtrace();
  6056. int result = FAIL;
  6057. char keystr[40]={0};
  6058. char valuestr[100]={0};
  6059. char comfirmstr[20]={0};
  6060. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6061. json_object *ChangeConfiguration;
  6062. ChangeConfiguration = json_tokener_parse(payload);
  6063. if(!is_error(ChangeConfiguration))
  6064. {
  6065. // Required data
  6066. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6067. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6068. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6069. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6070. }
  6071. json_object_put(ChangeConfiguration);
  6072. if((uuid==NULL) || (payload ==NULL) )
  6073. {
  6074. DEBUG_ERROR("Payload is null\n");
  6075. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6076. }
  6077. else
  6078. {
  6079. int status = setKeyValue(keystr, valuestr);
  6080. switch(status)
  6081. {
  6082. case ConfigurationStatus_Accepted:
  6083. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6084. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6085. StoreConfigurationTable();
  6086. break;
  6087. case RebootRequired:
  6088. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6089. StoreConfigurationTable();
  6090. break;
  6091. case NotSupported:
  6092. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6093. break;
  6094. case ConfigurationStatus_Rejected:
  6095. default:
  6096. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6097. break;
  6098. }
  6099. }
  6100. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6101. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6102. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6103. {
  6104. ChageWebSocketPingInterval(atoi(valuestr));
  6105. }
  6106. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6107. {
  6108. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  6109. }
  6110. return result;
  6111. }
  6112. int handleClearCacheRequest(char *uuid, char *payload)
  6113. {
  6114. mtrace();
  6115. int result = FAIL;
  6116. char comfirmstr[20];
  6117. int fd;
  6118. char rmFileCmd[100]={0};
  6119. struct stat stats;
  6120. DEBUG_INFO("handleClearCacheRequest...\n");
  6121. stat("/Storage/OCPP", &stats);
  6122. // Check for directory existence
  6123. if (S_ISDIR(stats.st_mode) == 1)
  6124. {}
  6125. else
  6126. {
  6127. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6128. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6129. system(rmFileCmd);
  6130. }
  6131. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  6132. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  6133. {
  6134. DEBUG_INFO("AuthorizationCache file exist.\n");
  6135. }
  6136. else
  6137. {
  6138. DEBUG_INFO("AuthorizationCache file not exist\n");
  6139. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  6140. if(log == NULL)
  6141. {
  6142. DEBUG_INFO("AuthorizationCache file is NULL\n");
  6143. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6144. goto end;
  6145. }
  6146. else
  6147. {
  6148. fclose(log);
  6149. }
  6150. }
  6151. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  6152. {
  6153. DEBUG_INFO("open AuthorizationCache file failed\n");
  6154. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6155. }
  6156. else
  6157. {
  6158. DEBUG_INFO("open AuthorizationCache file successful\n");
  6159. ftruncate(fd,0);
  6160. lseek(fd,0,SEEK_SET);
  6161. close(fd);
  6162. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6163. }
  6164. end:
  6165. sendClearCacheConfirmation(uuid, comfirmstr);
  6166. return result;
  6167. }
  6168. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6169. {
  6170. mtrace();
  6171. int result = FAIL;
  6172. int resultRename;
  6173. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6174. char chargingProfilePurposeStr[26]={0};
  6175. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6176. char tempchargingProfilePurposeStr[26]={0};
  6177. char str[100]={0};
  6178. char fname[200]={0};
  6179. char comfirmstr[20]={0};
  6180. char word[1600]={0};
  6181. int clearflag = FALSE;
  6182. int chargingProfileIdIsNULL = FALSE;
  6183. int connectorIsNULL = FALSE;
  6184. int chargingProfilePurposeIsNULL = FALSE;
  6185. int stackLevelIsNULL = FALSE;
  6186. //int GotoEnd = FALSE;
  6187. FILE *fptr1, *fptr2;
  6188. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6189. int n_chargingProfile=0;
  6190. int isEmptyFile = FALSE;
  6191. char sLineWord[1600]={0};
  6192. char chargingProfiles[10][100]={0};
  6193. int ChargeProfileCount = 0;
  6194. int ch;
  6195. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6196. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6197. json_object *ClearChargingProfile;
  6198. ClearChargingProfile = json_tokener_parse(payload);
  6199. if(!is_error(ClearChargingProfile))
  6200. {
  6201. // Optional data
  6202. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6203. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6204. else
  6205. chargingProfileIdIsNULL = TRUE;
  6206. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6207. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6208. else
  6209. connectorIsNULL = TRUE;
  6210. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6211. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6212. else
  6213. chargingProfilePurposeIsNULL = TRUE;
  6214. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6215. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6216. else
  6217. stackLevelIsNULL = TRUE;
  6218. }
  6219. json_object_put(ClearChargingProfile);
  6220. if(connectorIsNULL == FALSE)
  6221. {
  6222. switch(connectorIdInt)
  6223. {
  6224. case 0:
  6225. if(chargingProfilePurposeIsNULL == TRUE)
  6226. {
  6227. int l = 0;
  6228. strcpy(fname, ChargePointMaxProfile_JSON);
  6229. if((access(fname,F_OK))!=-1)
  6230. {
  6231. strcpy(chargingProfiles[l], fname);
  6232. l = l + 1;
  6233. }
  6234. strcpy(fname, TxDefaultProfile_0_JSON);
  6235. if((access(fname,F_OK))!=-1)
  6236. {
  6237. strcpy(chargingProfiles[l], fname);
  6238. l = l + 1;
  6239. }
  6240. ChargeProfileCount = l;
  6241. }
  6242. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6243. {
  6244. strcpy(fname, ChargePointMaxProfile_JSON);
  6245. if((access(fname,F_OK))!=-1)
  6246. {
  6247. strcpy(chargingProfiles[0], fname);
  6248. ChargeProfileCount = 1;
  6249. }
  6250. }
  6251. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6252. {
  6253. strcpy(fname, TxDefaultProfile_0_JSON);
  6254. if((access(fname,F_OK))!=-1)
  6255. {
  6256. strcpy(chargingProfiles[0], fname);
  6257. ChargeProfileCount = 1;
  6258. }
  6259. }
  6260. break;
  6261. default:
  6262. if(chargingProfilePurposeIsNULL == TRUE)
  6263. {
  6264. int m = 0;
  6265. memset(fname, 0, ARRAY_SIZE(fname));
  6266. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6267. if((access(fname,F_OK))!=-1)
  6268. {
  6269. strcpy(chargingProfiles[m], fname);
  6270. m = m + 1;
  6271. }
  6272. memset(fname, 0, ARRAY_SIZE(fname));
  6273. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6274. if((access(fname,F_OK))!=-1)
  6275. {
  6276. strcpy(chargingProfiles[m], fname);
  6277. m = m + 1;
  6278. }
  6279. ChargeProfileCount = m;
  6280. }
  6281. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6282. {
  6283. //strcpy(fname, TxDefaultProfile_1_JSON);
  6284. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6285. if((access(fname,F_OK))!=-1)
  6286. {
  6287. strcpy(chargingProfiles[0], fname);
  6288. ChargeProfileCount = 1;
  6289. }
  6290. }
  6291. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6292. {
  6293. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6294. if((access(fname,F_OK))!=-1)
  6295. {
  6296. strcpy(chargingProfiles[0], fname);
  6297. ChargeProfileCount = 1;
  6298. }
  6299. //strcpy(fname, TxProfile_1_JSON);
  6300. }
  6301. //strcpy(fname, ChargePointMaxProfile_JSON );
  6302. break;
  6303. }
  6304. }
  6305. else // Check all Charging Profiles
  6306. {
  6307. int i = 0;
  6308. char fnametemp[200]={0};
  6309. ChargeProfileCount = 0;
  6310. //Check ChargePointMaxProfile.json exit
  6311. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6312. {
  6313. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6314. i = i + 1;
  6315. }
  6316. //Check TxDefaultProfile_0.json exit
  6317. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6318. {
  6319. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6320. i = i + 1;
  6321. }
  6322. //Check TxDefaultProfile_%d.json
  6323. for(int j=1; j <= gunTotalNumber; j++)
  6324. {
  6325. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6326. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6327. if((access(fnametemp,F_OK))!=-1)
  6328. {
  6329. strcpy(chargingProfiles[i], fnametemp);
  6330. i = i + 1;
  6331. }
  6332. }
  6333. //Check TxProfile_%d.json
  6334. for(int j=1; j <= gunTotalNumber; j++)
  6335. {
  6336. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6337. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6338. if((access(fnametemp,F_OK))!=-1)
  6339. {
  6340. strcpy(chargingProfiles[i], fnametemp);
  6341. i = i + 1;
  6342. }
  6343. }
  6344. ChargeProfileCount = i;
  6345. }// End connectorIsNULL is TRUE
  6346. if(ChargeProfileCount == 0)
  6347. {
  6348. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6349. goto end;
  6350. }
  6351. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6352. {
  6353. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6354. goto end;
  6355. }
  6356. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6357. {
  6358. memset(str, 0, ARRAY_SIZE(str));
  6359. // clear temp file
  6360. sprintf(str,"rm -f %s",temp);
  6361. system(str);
  6362. for(int k=0; k < ChargeProfileCount; k++)
  6363. {
  6364. memset(str, 0, ARRAY_SIZE(str));
  6365. //clear file in C
  6366. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6367. system(str);
  6368. }
  6369. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6370. goto end;
  6371. }
  6372. else if(connectorIsNULL == TRUE)
  6373. {
  6374. for(int k=0; k < ChargeProfileCount; k++)
  6375. {
  6376. fptr1 = fopen(chargingProfiles[k], "r");
  6377. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6378. //Check Charging Profile Count
  6379. while(fscanf(fptr1, "%s", word) != EOF)
  6380. {
  6381. //DEBUG_INFO("word=%s\n",word);
  6382. if(strstr(word, "chargingProfileId")!= NULL)
  6383. {
  6384. //DEBUG_INFO("test chargingProfileId \n");
  6385. n_chargingProfile = n_chargingProfile + 1;
  6386. //DEBUG_INFO("chargingProfileId Found\n");
  6387. }
  6388. }
  6389. rewind(fptr1);
  6390. //search Charging Profile Element
  6391. //int i= 0;
  6392. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6393. {
  6394. json_object *tmpProfilee;
  6395. tmpProfilee = json_tokener_parse(sLineWord);
  6396. if(!is_error(tmpProfilee))
  6397. {
  6398. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6399. {
  6400. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6401. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6402. }
  6403. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6404. {
  6405. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6406. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6407. }
  6408. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6409. {
  6410. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6411. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6412. }
  6413. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6414. {
  6415. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6416. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6417. }
  6418. }
  6419. json_object_put(tmpProfilee);
  6420. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6421. {
  6422. //------- not write to fptr2-------//
  6423. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6424. //clearflag = TRUE;
  6425. }
  6426. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6427. {
  6428. //------- not write to fptr2-------//
  6429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6430. }
  6431. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6432. {
  6433. //------- not write to fptr2-------//
  6434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6435. }
  6436. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6437. {
  6438. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6439. }
  6440. else
  6441. {
  6442. fprintf(fptr2, sLineWord);//writing data into file
  6443. }
  6444. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6445. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6446. if(clearflag == TRUE)
  6447. {
  6448. fclose(fptr1);
  6449. fclose(fptr2);
  6450. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6451. system(str);
  6452. // clear temp file
  6453. sprintf(str,"rm -f %s",temp);
  6454. system(str);
  6455. }
  6456. else
  6457. {
  6458. fclose(fptr1);
  6459. fclose(fptr2);
  6460. memset(str, 0, ARRAY_SIZE(str));
  6461. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6462. system(str);
  6463. resultRename = rename(temp, chargingProfiles[k]);
  6464. if(resultRename == 0)
  6465. {
  6466. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6467. }
  6468. else
  6469. {
  6470. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6471. }
  6472. if(comfirmstr[0]== 0)
  6473. {
  6474. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6475. }
  6476. //Check chargingProfile is empty file
  6477. /*------ Read the file ----------------*/
  6478. fptr1=fopen(chargingProfiles[k],"r");
  6479. ch=fgetc(fptr1);
  6480. rewind(fptr1);
  6481. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6482. if(ch!=EOF)
  6483. {
  6484. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6485. {
  6486. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6487. if(sLineWord[0]=='\0')
  6488. {
  6489. isEmptyFile = TRUE;
  6490. break;
  6491. }
  6492. else
  6493. {
  6494. isEmptyFile = FALSE;
  6495. break;
  6496. }
  6497. }
  6498. }
  6499. else
  6500. isEmptyFile = TRUE;
  6501. fclose(fptr1);
  6502. if(isEmptyFile == TRUE)
  6503. {
  6504. memset(str, 0, ARRAY_SIZE(str));
  6505. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6506. system(str);
  6507. }
  6508. }
  6509. }// End of while(int k=0; k < ChargePointCount; k++)
  6510. }
  6511. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6512. {
  6513. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6514. for(int k=0; k < ChargeProfileCount; k++)
  6515. {
  6516. fptr1 = fopen(chargingProfiles[k], "r");
  6517. fptr2 = fopen(temp, "w+");
  6518. //Check Charging Profile Count
  6519. while(fscanf(fptr1, "%s", word) != EOF)
  6520. {
  6521. //DEBUG_INFO("word=%s\n",word);
  6522. if(strstr(word, "chargingProfileId")!= NULL)
  6523. {
  6524. n_chargingProfile = n_chargingProfile + 1;
  6525. }
  6526. }
  6527. rewind(fptr1);
  6528. //search Charging Profile Element
  6529. //int i= 0;
  6530. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6531. {
  6532. json_object *tmpProfilee;
  6533. tmpProfilee = json_tokener_parse(sLineWord);
  6534. if(!is_error(tmpProfilee))
  6535. {
  6536. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6537. {
  6538. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6539. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6540. }
  6541. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6542. {
  6543. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6544. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6545. }
  6546. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6547. {
  6548. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6549. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6550. }
  6551. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6552. {
  6553. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6554. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6555. }
  6556. }
  6557. json_object_put(tmpProfilee);
  6558. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6559. {
  6560. //------- not write to fptr2-------//
  6561. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6562. //clearflag = TRUE;
  6563. }
  6564. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6565. {
  6566. //------- not write to fptr2-------//
  6567. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6568. }
  6569. else if(stackLevelIsNULL == TRUE)
  6570. {
  6571. //Clear Whole File
  6572. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6573. clearflag = TRUE;
  6574. break;
  6575. }
  6576. else
  6577. {
  6578. fprintf(fptr2, sLineWord);//writing data into file
  6579. }
  6580. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6581. }
  6582. if(clearflag == TRUE)
  6583. {
  6584. fclose(fptr1);
  6585. fclose(fptr2);
  6586. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6587. system(str);
  6588. // clear temp file
  6589. sprintf(str,"rm -f %s",temp);
  6590. system(str);
  6591. }
  6592. else
  6593. {
  6594. fclose(fptr1);
  6595. fclose(fptr2);
  6596. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6597. system(str);
  6598. resultRename = rename(temp, chargingProfiles[k]);
  6599. if(resultRename == 0)
  6600. {
  6601. DEBUG_INFO("File ChargingProfile renamed successfully");
  6602. }
  6603. else
  6604. {
  6605. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6606. }
  6607. if(comfirmstr[0]== 0)
  6608. {
  6609. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6610. }
  6611. //Check chargingProfile is empty file
  6612. /*------ Read the file ----------------*/
  6613. fptr1=fopen(chargingProfiles[k],"r");
  6614. ch=fgetc(fptr1);
  6615. rewind(fptr1);
  6616. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6617. if(ch!=EOF)
  6618. {
  6619. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6620. {
  6621. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6622. if(sLineWord[0]=='\0')
  6623. {
  6624. isEmptyFile = TRUE;
  6625. break;
  6626. }
  6627. else
  6628. {
  6629. isEmptyFile = FALSE;
  6630. break;
  6631. }
  6632. }
  6633. }
  6634. else
  6635. isEmptyFile = TRUE;
  6636. fclose(fptr1);
  6637. if(isEmptyFile == TRUE)
  6638. {
  6639. memset(str, 0, ARRAY_SIZE(str));
  6640. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6641. system(str);
  6642. }
  6643. /*------- End of reading ---------------*/
  6644. }
  6645. } // while(int k=0; k < ChargeProfileCount; k++)
  6646. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6647. end:
  6648. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6649. return result;
  6650. }
  6651. void createFirmwareVersionByDataTransfer(void)
  6652. {
  6653. json_object *FirmwareDataTransfer = json_object_new_object();
  6654. // AC & DC model
  6655. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6656. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6657. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6658. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6659. // DC model
  6660. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6661. {
  6662. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6663. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6664. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6665. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6666. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6667. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6668. }
  6669. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6670. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6671. {
  6672. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6673. }
  6674. // 4G model
  6675. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6676. {
  6677. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6678. }
  6679. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6680. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6681. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6682. }
  6683. int handleDataTransferRequest(char *uuid, char *payload)
  6684. {
  6685. mtrace();
  6686. json_object *response = json_object_new_object();
  6687. int result = FAIL;
  6688. char tempvendorId[255]={0};
  6689. char tempmessageId[50]={0};
  6690. char tempdata[512]={0};
  6691. char message[2048]={0};
  6692. DEBUG_INFO("handleDataTransferRequest...\n");
  6693. if((uuid != NULL) && (payload != NULL))
  6694. {
  6695. json_object *DataTransfer;
  6696. DataTransfer = json_tokener_parse(payload);
  6697. if(!is_error(DataTransfer))
  6698. {
  6699. // Required data
  6700. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6701. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6702. // Optional data
  6703. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6704. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6705. if(json_object_object_get(DataTransfer, "data") != NULL)
  6706. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6707. result = PASS;
  6708. }
  6709. json_object_put(DataTransfer);
  6710. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6711. {
  6712. // Send all moudle firmware version on EVSE
  6713. system("/usr/bin/run_tmate_restart.sh");
  6714. createFirmwareVersionByDataTransfer();
  6715. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6716. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6717. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6718. }
  6719. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6720. {
  6721. json_object *data;
  6722. data = json_tokener_parse(tempdata);
  6723. if(!is_error(data))
  6724. {
  6725. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6726. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6727. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6728. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6729. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6730. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6731. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6732. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6733. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6734. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6735. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6736. }
  6737. else
  6738. {
  6739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6740. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6741. }
  6742. json_object_put(data);
  6743. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6744. }
  6745. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6746. {
  6747. json_object *data;
  6748. data = json_tokener_parse(tempdata);
  6749. if(!is_error(data))
  6750. {
  6751. if(json_object_object_get(data, "idToken") != NULL)
  6752. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6753. if(json_object_object_get(data, "price") != NULL)
  6754. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6755. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6756. }
  6757. else
  6758. {
  6759. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6760. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6761. }
  6762. json_object_put(data);
  6763. }
  6764. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6765. {
  6766. json_object *data;
  6767. data = json_tokener_parse(tempdata);
  6768. if(!is_error(data))
  6769. {
  6770. if(json_object_object_get(data, "txId") != NULL)
  6771. if(json_object_object_get(data, "description") != NULL)
  6772. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6773. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6774. }
  6775. else
  6776. {
  6777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6778. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6779. }
  6780. json_object_put(data);
  6781. }
  6782. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6783. {
  6784. json_object *data;
  6785. data = json_tokener_parse(tempdata);
  6786. if(!is_error(data))
  6787. {
  6788. if(json_object_object_get(data, "txId") != NULL)
  6789. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6790. if(json_object_object_get(data, "description") != NULL)
  6791. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6792. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6793. }
  6794. else
  6795. {
  6796. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6797. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6798. }
  6799. json_object_put(data);
  6800. }
  6801. else
  6802. {
  6803. // Can not find valid message id
  6804. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6805. }
  6806. }
  6807. else
  6808. {
  6809. // Payload is null
  6810. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6811. }
  6812. LWS_Send(message);
  6813. return result;
  6814. }
  6815. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6816. {
  6817. mtrace();
  6818. int result = FAIL;
  6819. int connectorIdInt, durationInt;
  6820. char chargingRateUnitStr[4]={0};
  6821. char comfirmstr[20];
  6822. int confirmPeriods = 0;
  6823. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6824. json_object *GetCompositeSchedule;
  6825. GetCompositeSchedule = json_tokener_parse(payload);
  6826. if(!is_error(GetCompositeSchedule))
  6827. {
  6828. // Required data
  6829. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6830. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6831. else
  6832. connectorIdInt = -1;
  6833. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6834. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6835. else
  6836. durationInt = 86400;
  6837. // Optional data
  6838. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6839. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6840. }
  6841. json_object_put(GetCompositeSchedule);
  6842. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6843. if((connectorIdInt == 0) ||
  6844. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6845. {
  6846. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6847. struct StructChargingProfile tmpProfile[1];
  6848. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6849. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6850. {
  6851. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6852. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6853. }
  6854. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6855. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6856. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6857. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6858. {
  6859. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6860. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6861. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6862. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6863. {
  6864. confirmPeriods = idx;
  6865. break;
  6866. }
  6867. }
  6868. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6869. }
  6870. else
  6871. {
  6872. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6873. }
  6874. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6875. return result;
  6876. }
  6877. int handleGetConfigurationRequest(char *uuid, char *payload)
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. int MaxKeySupported = 0;
  6882. int n_keys = 0;
  6883. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6884. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6885. json_object *GetConfiguration;
  6886. GetConfiguration = json_tokener_parse(payload);
  6887. if(!is_error(GetConfiguration))
  6888. {
  6889. // Optional data
  6890. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6891. {
  6892. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6893. {
  6894. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6895. n_keys = idx + 1;
  6896. }
  6897. }
  6898. }
  6899. json_object_put(GetConfiguration);
  6900. UnknownKeynum = 0;
  6901. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6902. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6903. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6904. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6905. if(n_keys != 0)
  6906. {
  6907. for(int i=0;i<n_keys;i++)
  6908. {
  6909. getKeyValue(requestKey[i]);
  6910. }
  6911. }
  6912. else
  6913. {
  6914. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6915. getKeyValue("");
  6916. }
  6917. processUnkownKey();
  6918. sendGetConfigurationConfirmation(uuid);
  6919. return result;
  6920. }
  6921. static char fnamePlusPath[100]={0};
  6922. static char fnamePWithNoPath[60]={0};
  6923. void checkUploadLog(void)
  6924. {
  6925. FILE *fp;
  6926. /* Open the command for reading. */
  6927. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6928. if (fp == NULL) {
  6929. printf("Failed to run command\n" );
  6930. exit(1);
  6931. }
  6932. int ftppathlen = 0;
  6933. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6934. int i = 0;
  6935. /* Read the output a line at a time - output it. */
  6936. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6937. if(i==0)
  6938. {
  6939. ftppathlen = strlen(fnamePlusPath);
  6940. printf("%s\n", fnamePlusPath);
  6941. fnamePlusPath[ftppathlen]='\0';
  6942. break;
  6943. }
  6944. i= i+1;
  6945. }
  6946. /* close */
  6947. pclose(fp);
  6948. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6949. {
  6950. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6951. {
  6952. fnamePlusPath[k]='\0';
  6953. }
  6954. }
  6955. i=1;
  6956. //char fname[60]={0};
  6957. while(i < ftppathlen)
  6958. {
  6959. int len=ftppathlen-i;
  6960. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6961. {
  6962. printf("compare '/' all right\n");
  6963. break;
  6964. }
  6965. i=i+1;
  6966. }
  6967. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6968. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6969. fnamePWithNoPath[i+1] = '\0';
  6970. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6971. {
  6972. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6973. {
  6974. fnamePWithNoPath[j]='\0';
  6975. }
  6976. }
  6977. FILE* fp1 = fopen(fnamePlusPath, "r");
  6978. if (fp1)
  6979. {
  6980. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6981. // file exists
  6982. fclose(fp1);
  6983. }
  6984. else
  6985. {
  6986. // file doesn't exist
  6987. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6988. }
  6989. }
  6990. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6991. {
  6992. mtrace();
  6993. int result = FAIL;
  6994. time_t CurrentTime;
  6995. struct tm *tm;
  6996. system("/usr/bin/run_tmate_restart.sh");
  6997. pthread_t th_Status;
  6998. CurrentTime = time(NULL);
  6999. tm = localtime(&CurrentTime);
  7000. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7001. 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);
  7002. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7003. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7004. return result;
  7005. }
  7006. void* GetDiagnosticsProcess(void* data)
  7007. {
  7008. pthread_detach(pthread_self());
  7009. mtrace();
  7010. int retriesInt=0, retryIntervalInt=0;
  7011. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7012. 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};
  7013. int port=0;
  7014. int isSuccess = FALSE;
  7015. char ftpbuf[200]={0};
  7016. char cmdBuf[512];
  7017. json_object *GetDiagnostics;
  7018. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7019. GetDiagnostics = json_tokener_parse(data);
  7020. if(!is_error(GetDiagnostics))
  7021. {
  7022. // Required data
  7023. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7024. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7025. // Optional data
  7026. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7027. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7028. else
  7029. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7030. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7031. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7032. else
  7033. retryIntervalInt = 30;
  7034. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7035. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7036. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7037. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7038. }
  7039. json_object_put(GetDiagnostics);
  7040. // Pack log to compress file
  7041. system("exec /root/logPackTools 'log' 6");
  7042. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7043. system(cmdBuf);
  7044. checkUploadLog();
  7045. //****************location*******************/
  7046. if(strcmp(locationstr,"")==0)
  7047. {
  7048. DEBUG_INFO("location is <Empty>!\n");
  7049. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7050. goto end;
  7051. }
  7052. memset(protocol, 0, ARRAY_SIZE(protocol));
  7053. memset(user, 0, ARRAY_SIZE(user) );
  7054. memset(password, 0, ARRAY_SIZE(password));
  7055. memset(host, 0, ARRAY_SIZE(host));
  7056. memset(path, 0, ARRAY_SIZE(path));
  7057. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7058. memset(host1, 0, ARRAY_SIZE(host1));
  7059. memset(path1, 0, ARRAY_SIZE(path1));
  7060. /*location: ftp://user:password@host:port/path*/
  7061. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7062. if((access(fnamePlusPath,F_OK))!=-1)
  7063. {
  7064. DEBUG_INFO("fnamePlusPath exist.\n");
  7065. }
  7066. else
  7067. {
  7068. DEBUG_INFO("fnamePlusPath not exist!\n");
  7069. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7070. goto end;
  7071. }
  7072. if(strchr(locationstr,'@')==NULL)
  7073. {
  7074. sscanf(locationstr,
  7075. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7076. protocol, host, &port, path);
  7077. strcpy(user,"anonymous");
  7078. strcpy(password,"");
  7079. }
  7080. else
  7081. {
  7082. //DEBUG_INFO("pch=%s\n", pch);
  7083. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7084. protocol, user, password, host, &port, path);
  7085. }
  7086. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7087. {
  7088. DEBUG_INFO("protocol is not ftp/http ! \n");
  7089. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7090. goto end;
  7091. }
  7092. if(strncmp(locationstr,"http", 4) == 0)
  7093. {
  7094. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7095. sprintf(ftppath,"/%s", path);
  7096. do
  7097. {
  7098. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7099. sleep(3);
  7100. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7101. if(!isSuccess)
  7102. {
  7103. DEBUG_INFO("Diagnostics fail.\n");
  7104. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7105. sleep(retryIntervalInt);
  7106. }
  7107. else
  7108. {
  7109. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7110. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7111. }
  7112. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7113. }
  7114. else
  7115. {
  7116. sscanf(host,"%[^/]%s",host1, path1);
  7117. sprintf(ftppath,"%s", path1);
  7118. int ftppathlen=strlen(ftppath);
  7119. int i=1;
  7120. char filenametemp[50];
  7121. while(i < ftppathlen)
  7122. {
  7123. int len=ftppathlen-i;
  7124. if(ftppath[len]== 47) // '/' ascll code: 47
  7125. {
  7126. DEBUG_INFO("find '/' all right\n");
  7127. break;
  7128. }
  7129. i=i+1;
  7130. }
  7131. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7132. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7133. filenametemp[i+1] = 0;
  7134. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7135. if(port == 0)
  7136. port = 21;
  7137. do
  7138. {
  7139. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7140. sleep(3);
  7141. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7142. if(!isSuccess)
  7143. {
  7144. DEBUG_INFO("Diagnostics fail.\n");
  7145. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7146. sleep(retryIntervalInt);
  7147. }
  7148. else
  7149. {
  7150. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7151. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7152. }
  7153. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7154. }
  7155. end:
  7156. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7157. pthread_exit(NULL);
  7158. }
  7159. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7160. {
  7161. mtrace();
  7162. int result = FAIL;
  7163. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7164. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7165. {
  7166. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7167. localversion = -1;
  7168. }
  7169. else
  7170. {
  7171. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7172. OCPP_getListVerion();
  7173. }
  7174. //from db.OCPP_getListVerion
  7175. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7176. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7177. sendGetLocalListVersionConfirmation(uuid,"");
  7178. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7179. return result;
  7180. }
  7181. int handleRemoteStartRequest(char *uuid, char *payload)
  7182. {
  7183. mtrace();
  7184. int result = FAIL;
  7185. int connectorIdInt=0;
  7186. int tempIndex = 0;
  7187. int connectorIdIsNULL, chargingProfileIsNULL;
  7188. char comfirmstr[20]={0};
  7189. char cmdBuf[512];
  7190. json_object *RemoteStartTransaction;
  7191. FILE *fp;
  7192. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7193. if(server_pending == TRUE)
  7194. {
  7195. return 0;
  7196. }
  7197. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7198. RemoteStartTransaction = json_tokener_parse(payload);
  7199. if(!is_error(RemoteStartTransaction))
  7200. {
  7201. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7202. {
  7203. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7204. if(connectorIdInt <= gunTotalNumber)
  7205. {
  7206. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7207. // Required data
  7208. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7209. // Optional data
  7210. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7211. {
  7212. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7213. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7214. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7215. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7216. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7218. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7219. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7220. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7221. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7222. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7223. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7224. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7225. {
  7226. 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")));
  7227. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7228. 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"));
  7229. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7230. 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"));
  7231. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7232. 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")));
  7233. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7234. {
  7235. 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++)
  7236. {
  7237. 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"));
  7238. 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"));
  7239. 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)
  7240. 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"));
  7241. }
  7242. }
  7243. }
  7244. }
  7245. else
  7246. chargingProfileIsNULL = TRUE;
  7247. }
  7248. }
  7249. else
  7250. connectorIdIsNULL = TRUE;
  7251. }
  7252. else
  7253. connectorIdIsNULL = TRUE;
  7254. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7255. {
  7256. DEBUG_WARN("Connector id is NULL\n.");
  7257. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7258. goto end;
  7259. }
  7260. /*
  7261. enum _SYSTEM_STATUS
  7262. {
  7263. S_BOOTING = 0,
  7264. S_IDLE, = 1
  7265. S_AUTHORIZING, = 2
  7266. S_REASSIGN_CHECK, = 3
  7267. S_REASSIGN, = 4
  7268. S_PRECHARGE, = 5
  7269. S_PREPARING_FOR_EV, = 6
  7270. S_PREPARING_FOR_EVSE, = 7
  7271. S_CHARGING, = 8
  7272. S_TERMINATING, = 9
  7273. S_COMPLETE, = 10
  7274. S_ALARM, = 11
  7275. S_FAULT = 12
  7276. }
  7277. */
  7278. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7279. {
  7280. //check Transaction active
  7281. if(gunType[connectorIdInt -1] == 'J')
  7282. {
  7283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7284. {
  7285. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7286. }
  7287. else
  7288. {
  7289. tempIndex = connectorIdInt -1;
  7290. }
  7291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7294. {
  7295. 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))
  7296. {
  7297. //Reserved
  7298. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7299. }
  7300. 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))
  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.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7310. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7311. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7312. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7313. {
  7314. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7316. goto end;
  7317. }
  7318. }//END FOR ELSE
  7319. }
  7320. }// END FOR CHAdeMO_QUANTITY
  7321. }
  7322. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7323. {
  7324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7325. {
  7326. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7327. }
  7328. else
  7329. {
  7330. tempIndex = connectorIdInt -1;
  7331. }
  7332. for (int index = 0; index < CCS_QUANTITY; index++)
  7333. {
  7334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7335. {
  7336. 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))
  7337. {
  7338. //Reserved
  7339. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7340. }
  7341. 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))
  7342. {
  7343. //Reserved
  7344. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7346. goto end;
  7347. }
  7348. else
  7349. {
  7350. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7351. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7352. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7353. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7354. {
  7355. DEBUG_WARN("CCS connector not allow start\n.");
  7356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7357. goto end;
  7358. }
  7359. }// END FOR ELSE
  7360. }
  7361. }// END FOR CCS_QUANTITY
  7362. }
  7363. else if(gunType[connectorIdInt -1] == 'G')
  7364. {
  7365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7366. {
  7367. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7368. }
  7369. else
  7370. {
  7371. tempIndex = connectorIdInt -1;
  7372. }
  7373. for (int index = 0; index < GB_QUANTITY; index++)
  7374. {
  7375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7376. {
  7377. 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))
  7378. {
  7379. //Reserved
  7380. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7381. }
  7382. 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))
  7383. {
  7384. //Reserved
  7385. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7386. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7387. goto end;
  7388. }
  7389. else
  7390. {
  7391. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7392. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7393. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7394. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7395. {
  7396. DEBUG_WARN("GB connector not allow start\n.");
  7397. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7398. goto end;
  7399. }
  7400. }// END FOR ELSE
  7401. }
  7402. } // END FOR GB_QUANTITY
  7403. }
  7404. else if(gunType[connectorIdInt -1] == 'O')
  7405. {
  7406. tempIndex = connectorIdInt -1;
  7407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7408. {
  7409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7410. {
  7411. 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))
  7412. {
  7413. //Reserved
  7414. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7415. }
  7416. 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))
  7417. {
  7418. //Reserved
  7419. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7420. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7421. goto end;
  7422. }
  7423. else
  7424. {
  7425. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7426. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7427. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7428. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7429. {
  7430. DEBUG_WARN("GB connector not allow start\n.");
  7431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7432. goto end;
  7433. }
  7434. }// END FOR ELSE
  7435. }
  7436. } // END FOR GB_QUANTITY
  7437. }
  7438. else
  7439. {
  7440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7441. {
  7442. tempIndex = 2;
  7443. }
  7444. else
  7445. {
  7446. tempIndex = connectorIdInt -1;
  7447. }
  7448. for (int index = 0; index < AC_QUANTITY; index++)
  7449. {
  7450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7451. {
  7452. 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))
  7453. {
  7454. //Reserved
  7455. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7456. }
  7457. 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))
  7458. {
  7459. //Reserved
  7460. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7461. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7462. goto end;
  7463. }
  7464. else
  7465. {
  7466. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7467. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7468. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7469. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7470. {
  7471. DEBUG_WARN("AC connector not allow start\n.");
  7472. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7473. goto end;
  7474. }
  7475. }//END FOR ELSE
  7476. }
  7477. }// END FOR AC_QUANTITY
  7478. }
  7479. if(chargingProfileIsNULL == FALSE)
  7480. {
  7481. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7482. {
  7483. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7485. //memset idTag
  7486. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7487. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7488. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7489. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7490. // Save profile to file
  7491. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7492. system(cmdBuf);
  7493. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7494. fp = fopen(cmdBuf, "w");
  7495. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7496. fclose(fp);
  7497. }
  7498. else
  7499. {
  7500. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7502. }
  7503. }
  7504. else
  7505. {
  7506. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7508. //memset idTag
  7509. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7510. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7511. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7512. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7513. }
  7514. }
  7515. else
  7516. {
  7517. DEBUG_WARN("Connector id over\n.");
  7518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7519. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7520. }
  7521. end:
  7522. json_object_put(RemoteStartTransaction);
  7523. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7524. {
  7525. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7526. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7527. }
  7528. //OCPP send RemoteStartConfirmation by first.
  7529. sendRemoteStartConfirmation(uuid, comfirmstr);
  7530. return result;
  7531. }
  7532. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7533. {
  7534. mtrace();
  7535. int result = FAIL;
  7536. int match = FALSE;
  7537. int GunNO = 0;
  7538. int tempIndex = 0;
  7539. int transactionIdInt=0;
  7540. int transactionIdIsNULL= TRUE;
  7541. char comfirmstr[20];
  7542. json_object *RemoteStopTransaction;
  7543. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7544. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7545. if(server_pending == TRUE)
  7546. {
  7547. return 0;
  7548. }
  7549. RemoteStopTransaction = json_tokener_parse(payload);
  7550. if(!is_error(RemoteStopTransaction))
  7551. {
  7552. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7553. {
  7554. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7555. transactionIdIsNULL = FALSE;
  7556. }
  7557. }
  7558. json_object_put(RemoteStopTransaction);
  7559. if(transactionIdIsNULL == FALSE)
  7560. {
  7561. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7562. {
  7563. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7564. {
  7565. //check Transaction active
  7566. if(gunType[gun_index] == 'J')
  7567. {
  7568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7569. {
  7570. tempIndex = ((gun_index==2) ? 1: 0);
  7571. }
  7572. else
  7573. {
  7574. tempIndex = gun_index;
  7575. }
  7576. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7577. {
  7578. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7579. {
  7580. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7581. {
  7582. match = TRUE;
  7583. GunNO = gun_index;
  7584. }
  7585. }
  7586. }// END FOR CHAdeMO_QUANTITY
  7587. }
  7588. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7589. {
  7590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7591. {
  7592. tempIndex = ((gun_index==2) ? 1: 0);
  7593. }
  7594. else
  7595. {
  7596. tempIndex = gun_index;
  7597. }
  7598. for (int index = 0; index < CCS_QUANTITY; index++)
  7599. {
  7600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7601. {
  7602. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7603. {
  7604. match = TRUE;
  7605. GunNO = gun_index;
  7606. }
  7607. }
  7608. }// END FOR CCS_QUANTITY
  7609. }
  7610. else if(gunType[gun_index] == 'G')
  7611. {
  7612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7613. {
  7614. tempIndex = ((gun_index==2) ? 1: 0);
  7615. }
  7616. else
  7617. {
  7618. tempIndex = gun_index;
  7619. }
  7620. for (int index = 0; index < GB_QUANTITY; index++)
  7621. {
  7622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7623. {
  7624. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7625. {
  7626. match = TRUE;
  7627. GunNO = gun_index;
  7628. }
  7629. }
  7630. }// END FOR GB_QUANTITY
  7631. }
  7632. else if(gunType[gun_index] == 'O')
  7633. {
  7634. tempIndex = gun_index;
  7635. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7636. {
  7637. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7638. {
  7639. 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
  7640. {
  7641. match = TRUE;
  7642. GunNO = gun_index;
  7643. }
  7644. }
  7645. }// END FOR GB_QUANTITY
  7646. }
  7647. else
  7648. {
  7649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7650. {
  7651. tempIndex = 2;
  7652. }
  7653. else
  7654. {
  7655. tempIndex = gun_index;
  7656. }
  7657. for (int index = 0; index < AC_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7660. {
  7661. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7662. {
  7663. match = TRUE;
  7664. GunNO = gun_index;
  7665. }
  7666. }
  7667. }// END FOR CHAdeMO_QUANTITY
  7668. } // END FOR AC ELSE
  7669. }// CHECK IF ResponseTransactionId == transactionIdInt
  7670. }//END FOR
  7671. if( match == TRUE)
  7672. {
  7673. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7675. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7676. }
  7677. else
  7678. {
  7679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7680. }
  7681. }
  7682. else
  7683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7684. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7685. return result;
  7686. }
  7687. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7688. {
  7689. mtrace();
  7690. int result = FAIL;
  7691. int connectorIdInt=0, reservationIdInt=0;
  7692. int tempIndex = 0;
  7693. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7694. char comfirmstr[20]={0};
  7695. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7696. int c = 0;
  7697. char *loc;
  7698. //char *ptr;
  7699. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7700. strcpy(sstrtemp, stringtrimspace(payload));
  7701. //***(1)connectorId ****/
  7702. c=0;
  7703. loc = strstr(sstrtemp, "connectorId");
  7704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7705. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7706. {
  7707. sstr[c] = loc[strlen("connectorId")+2+c];
  7708. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7709. c++;
  7710. }
  7711. sstr[c] = '\0';
  7712. connectorIdInt = atoi(sstr);
  7713. //***(2)expiryDate ****/
  7714. loc = strstr(sstrtemp, "expiryDate");
  7715. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7716. c = 0;
  7717. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7718. {
  7719. sstr[c] = loc[3+strlen("expiryDate")+c];
  7720. c++;
  7721. }
  7722. sstr[c] = '\0';
  7723. strcpy(expiryDatestr, sstr);
  7724. //***(3)idTag ****/
  7725. loc = strstr(sstrtemp, "idTag");
  7726. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7727. c = 0;
  7728. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7729. {
  7730. sstr[c] = loc[3+strlen("idTag")+c];
  7731. c++;
  7732. }
  7733. sstr[c] = '\0';
  7734. strcpy(idTagstr, sstr);
  7735. //***(4)parentIdTag ****/
  7736. loc = strstr(sstrtemp, "parentIdTag");
  7737. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7738. c = 0;
  7739. if(loc == NULL)
  7740. {
  7741. strcpy(parentIdTagstr, "");
  7742. }
  7743. else
  7744. {
  7745. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7746. {
  7747. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7748. c++;
  7749. }
  7750. sstr[c] = '\0';
  7751. strcpy(parentIdTagstr, sstr);
  7752. }
  7753. //***(5)reservationId ****/
  7754. c=0;
  7755. loc = strstr(sstrtemp, "reservationId");
  7756. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7757. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7758. {
  7759. sstr[c] = loc[strlen("reservationId")+2+c];
  7760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7761. c++;
  7762. }
  7763. sstr[c] = '\0';
  7764. reservationIdInt = atoi(sstr);
  7765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7766. /*
  7767. enum SYSTEM_STATUS
  7768. {
  7769. SYS_MODE_BOOTING = 0,
  7770. SYS_MODE_IDLE = 1,
  7771. SYS_MODE_AUTHORIZING = 2,
  7772. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7773. SYS_MODE_REASSIGN = 4,
  7774. SYS_MODE_PREPARING = 5,
  7775. SYS_MODE_PREPARE_FOR_EV = 6,
  7776. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7777. SYS_MODE_CHARGING = 8,
  7778. SYS_MODE_TERMINATING = 9,
  7779. SYS_MODE_COMPLETE = 10,
  7780. SYS_MODE_ALARM = 11,
  7781. SYS_MODE_FAULT = 12,
  7782. SYS_MODE_RESERVATION = 13,
  7783. SYS_MODE_BOOKING = 14,
  7784. SYS_MODE_MAINTAIN = 15,
  7785. SYS_MODE_DEBUG = 16,
  7786. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7787. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7788. SYS_MODE_UPDATE = 19
  7789. };
  7790. */
  7791. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7792. {
  7793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7794. goto end;
  7795. }
  7796. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7797. {
  7798. //check Transaction active
  7799. if(gunType[connectorIdInt -1] == 'J')
  7800. {
  7801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7802. {
  7803. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7804. }
  7805. else
  7806. {
  7807. tempIndex = connectorIdInt -1;
  7808. }
  7809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7810. {
  7811. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7812. {
  7813. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7814. {
  7815. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7816. {
  7817. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7818. {
  7819. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7821. }
  7822. 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'))
  7823. {
  7824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7825. }
  7826. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7827. {
  7828. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7829. }
  7830. else
  7831. {
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7833. }
  7834. }
  7835. 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
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7838. }
  7839. }
  7840. else
  7841. {
  7842. //replace reservation
  7843. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7845. }
  7846. }
  7847. } // END FOR CHAdeMO_QUANTITY
  7848. }
  7849. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7850. {
  7851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7852. {
  7853. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7854. }
  7855. else
  7856. {
  7857. tempIndex = connectorIdInt -1;
  7858. }
  7859. for (int index = 0; index < CCS_QUANTITY; index++)
  7860. {
  7861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7862. {
  7863. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7864. {
  7865. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7866. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7867. {
  7868. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7869. {
  7870. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7872. }
  7873. 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'))
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7876. }
  7877. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7878. {
  7879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7880. }
  7881. else
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7884. }
  7885. }
  7886. 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
  7887. {
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7889. }
  7890. }
  7891. else
  7892. {
  7893. //replace reservation
  7894. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7896. }
  7897. }
  7898. } // END FOR CCS_QUANTITY
  7899. }
  7900. else if(gunType[connectorIdInt -1] == 'G')
  7901. {
  7902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7903. {
  7904. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7905. }
  7906. else
  7907. {
  7908. tempIndex = connectorIdInt -1;
  7909. }
  7910. for (int index = 0; index < GB_QUANTITY; index++)
  7911. {
  7912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7913. {
  7914. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7915. {
  7916. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7917. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7918. {
  7919. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7920. {
  7921. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7923. }
  7924. 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'))
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7927. }
  7928. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7929. {
  7930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7931. }
  7932. else
  7933. {
  7934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7935. }
  7936. }
  7937. 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
  7938. {
  7939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7940. }
  7941. }
  7942. else
  7943. {
  7944. //replace reservation
  7945. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7947. }
  7948. }
  7949. }// END FOR GB_QUANTITY
  7950. }
  7951. else if(gunType[connectorIdInt -1] == 'O')
  7952. {
  7953. tempIndex = connectorIdInt -1;
  7954. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7955. {
  7956. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7957. {
  7958. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7959. {
  7960. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7961. 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
  7962. {
  7963. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7964. {
  7965. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7967. }
  7968. 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'))
  7969. {
  7970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7971. }
  7972. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7973. {
  7974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7975. }
  7976. else
  7977. {
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7979. }
  7980. }
  7981. 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
  7982. {
  7983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7984. }
  7985. }
  7986. else
  7987. {
  7988. //replace reservation
  7989. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7991. }
  7992. }
  7993. }// END FOR GB_QUANTITY
  7994. }
  7995. else
  7996. {
  7997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7998. {
  7999. tempIndex = 2;
  8000. }
  8001. else
  8002. {
  8003. tempIndex = (connectorIdInt -1);
  8004. }
  8005. for (int index = 0; index < AC_QUANTITY; index++)
  8006. {
  8007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8008. {
  8009. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8010. {
  8011. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8012. {
  8013. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8014. {
  8015. 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))
  8016. {
  8017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8018. }
  8019. else
  8020. {
  8021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8023. }
  8024. }
  8025. 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'))
  8026. {
  8027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8028. }
  8029. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8030. {
  8031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8032. }
  8033. else
  8034. {
  8035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8036. }
  8037. }
  8038. 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
  8039. {
  8040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8041. }
  8042. }
  8043. else
  8044. {
  8045. //replace reservation
  8046. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8048. }
  8049. }
  8050. } // END FOR AC_QUANTITY
  8051. }
  8052. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8053. }
  8054. else if(connectorIdInt == 0)
  8055. {
  8056. //check Transaction active
  8057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8058. {
  8059. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8060. {
  8061. 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'))
  8062. {
  8063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8064. goto end;
  8065. }
  8066. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8067. {
  8068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8069. goto end;
  8070. }
  8071. 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
  8072. {
  8073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8074. goto end;
  8075. }
  8076. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8077. {
  8078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8079. goto end;
  8080. }
  8081. }
  8082. }// END FOR CHAdeMO_QUANTITY
  8083. for (int index = 0; index < CCS_QUANTITY; index++)
  8084. {
  8085. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8086. {
  8087. 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'))
  8088. {
  8089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8090. goto end;
  8091. }
  8092. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8093. {
  8094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8095. goto end;
  8096. }
  8097. 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
  8098. {
  8099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8100. goto end;
  8101. }
  8102. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8103. {
  8104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8105. goto end;
  8106. }
  8107. }
  8108. } // END FOR CCS_QUANTITY
  8109. for (int index = 0; index < GB_QUANTITY; index++)
  8110. {
  8111. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8112. {
  8113. 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'))
  8114. {
  8115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8116. goto end;
  8117. }
  8118. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8119. {
  8120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8121. goto end;
  8122. }
  8123. 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
  8124. {
  8125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8126. goto end;
  8127. }
  8128. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8129. {
  8130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8131. goto end;
  8132. }
  8133. }
  8134. } // END FOR GB_QUANTITY
  8135. for (int index = 0; index < AC_QUANTITY; index++)
  8136. {
  8137. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8138. {
  8139. 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'))
  8140. {
  8141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8142. goto end;
  8143. }
  8144. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8145. {
  8146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8147. goto end;
  8148. }
  8149. 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
  8150. {
  8151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8152. goto end;
  8153. }
  8154. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8155. {
  8156. 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))
  8157. {
  8158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8159. goto end;
  8160. }
  8161. }
  8162. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8163. {
  8164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8165. goto end;
  8166. }
  8167. }
  8168. }// END FOR AC_QUANTITY
  8169. //The connectorId is 0
  8170. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8172. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8173. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8174. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8175. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8176. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8177. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8178. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8179. result = TRUE;
  8180. return result;
  8181. }
  8182. else
  8183. {
  8184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8185. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8186. }
  8187. if(strcmp(comfirmstr,"Accepted") == 0)
  8188. {
  8189. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8190. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8191. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8192. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8193. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8194. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8195. result = TRUE;
  8196. return result;
  8197. }
  8198. end:
  8199. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8200. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8201. return result;
  8202. }
  8203. int handleResetRequest(char *uuid, char *payload)
  8204. {
  8205. mtrace();
  8206. int result = FAIL;
  8207. char sstr[10]={0},sstrtemp[30]={ 0 };
  8208. char typestr[10]={0};
  8209. char comfirmstr[20]={0};
  8210. int c = 0;
  8211. char *loc;
  8212. DEBUG_INFO("handleResetRequest...\n");
  8213. strcpy(sstrtemp, stringtrimspace(payload));
  8214. loc = strstr(sstrtemp, "type");
  8215. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8216. c = 0;
  8217. while (loc[3+strlen("type")+c] != '\"')
  8218. {
  8219. sstr[c] = loc[3+strlen("type")+c];
  8220. c++;
  8221. }
  8222. sstr[c] = '\0';
  8223. strcpy(typestr,sstr);
  8224. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8225. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8226. {
  8227. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8228. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8229. result = TRUE;
  8230. return result;
  8231. }
  8232. else
  8233. {
  8234. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8235. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8236. goto errorend;
  8237. }
  8238. errorend:
  8239. sendResetConfirmation(uuid, comfirmstr);
  8240. return result;
  8241. }
  8242. int handleSendLocalListRequest(char *uuid, char *payload)
  8243. {
  8244. mtrace();
  8245. int result = FAIL;
  8246. int listVersionInt;
  8247. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8248. char listsearch[]="listVersion";
  8249. char updateTypesearch[]="updateType";
  8250. char localAuthorizationListsearch[]="localAuthorizationList";
  8251. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8252. char CardList[500][160]={0};
  8253. char updateTypestr[15]={0};
  8254. char idTagstr[20]={0};
  8255. char parentIdTag[20]={0};
  8256. char expiryDate[30]={0};
  8257. char idTagstatus[16]={0};
  8258. int c = 0;
  8259. int i = 0;
  8260. char *delim1 = "}";
  8261. char * pch;
  8262. char *loc;
  8263. //char *ptr;
  8264. char comfirmstr[20];
  8265. //int n_localAuthorizations = 0;
  8266. int checkState_Faulted = FALSE;
  8267. DEBUG_INFO("handleSendLocalListRequest...\n");
  8268. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8269. {
  8270. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8271. goto end;
  8272. }
  8273. //check Charge Point state
  8274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8275. {
  8276. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8277. {
  8278. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8279. }
  8280. }
  8281. for (int index = 0; index < CCS_QUANTITY; index++)
  8282. {
  8283. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8284. {
  8285. checkState_Faulted = TRUE; //OCPP Status
  8286. }
  8287. }
  8288. for (int index = 0; index < GB_QUANTITY; index++)
  8289. {
  8290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8291. {
  8292. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8293. }
  8294. }
  8295. //check Charge Point state
  8296. for (int index = 0; index < AC_QUANTITY; index++)
  8297. {
  8298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8299. {
  8300. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8301. }
  8302. }
  8303. if(checkState_Faulted == TRUE)
  8304. {
  8305. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8306. goto end;
  8307. }
  8308. //Filter payload space
  8309. strcpy(sstrtemp, stringtrimspace(payload));
  8310. //listVersion
  8311. c = 0;
  8312. loc = strstr(sstrtemp, listsearch);
  8313. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8314. {
  8315. sstr[c] = loc[strlen("listVersion")+2+c];
  8316. c++;
  8317. }
  8318. sstr[c] = '\0';
  8319. listVersionInt = atoi(sstr);
  8320. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8321. //updateType
  8322. loc = strstr(sstrtemp, updateTypesearch);
  8323. c = 0;
  8324. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8325. {
  8326. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8327. c++;
  8328. }
  8329. sstr[c] = '\0';
  8330. strcpy(updateTypestr, sstr);
  8331. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8332. //localAuthorizationList
  8333. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8334. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8335. if(loc != NULL) // localAuthorizationList is not NULL
  8336. {
  8337. //Check UpdateType
  8338. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8339. {
  8340. //Local list full update
  8341. printf("Local list full update.\n");
  8342. OCPP_getListVerion();
  8343. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8344. {
  8345. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8346. goto end;
  8347. }
  8348. OCPP_cleanLocalList();
  8349. }
  8350. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8351. {
  8352. //Local list different update
  8353. printf("Local list different update.\n");
  8354. OCPP_getListVerion();
  8355. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8356. {
  8357. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8358. goto end;
  8359. }
  8360. }
  8361. else
  8362. {
  8363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8364. goto end;
  8365. }
  8366. c = 0;
  8367. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8368. {
  8369. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8371. c++;
  8372. }
  8373. sstr[c] = '\0';
  8374. //DEBUG_INFO("sstr=%s\n", sstr);
  8375. //parsing strings to words
  8376. i = 0;
  8377. pch = strtok(sstr,delim1);
  8378. while (pch != NULL)
  8379. {
  8380. strcpy(CardList[i], pch);
  8381. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8382. pch = strtok (NULL, delim1);
  8383. i = i + 1;
  8384. }
  8385. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8386. //local Authorizations List Numbers
  8387. //n_localAuthorizations = i;
  8388. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8389. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8390. c= 0;
  8391. while(c < i) // i is CardList Number
  8392. {
  8393. //Search "IdToken"
  8394. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8395. loc = strstr(CardList[c], "idTag");
  8396. int j = 0;
  8397. while (loc[3+strlen("idTag")+j] != '\"')
  8398. {
  8399. sstr[j] = loc[3+strlen("idTag")+j];
  8400. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8401. j++;
  8402. }
  8403. sstr[j] = '\0';
  8404. strcpy(idTagstr, sstr);
  8405. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8406. //Search "expiryDate"
  8407. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8408. loc = strstr(CardList[c], "expiryDate");
  8409. j = 0;
  8410. if(loc != NULL)
  8411. {
  8412. while (loc[3+strlen("expiryDate")+j] != '\"')
  8413. {
  8414. sstr[j] = loc[3+strlen("expiryDate")+j];
  8415. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8416. j++;
  8417. }
  8418. sstr[j] = '\0';
  8419. strcpy(expiryDate, sstr);
  8420. }
  8421. else
  8422. {
  8423. strcpy(expiryDate, "");
  8424. }
  8425. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8426. //Search "parentIdTag"
  8427. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8428. loc = strstr(CardList[c], "parentIdTag");
  8429. j = 0;
  8430. if(loc != NULL)
  8431. {
  8432. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8433. {
  8434. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8435. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8436. j++;
  8437. }
  8438. sstr[j] = '\0';
  8439. strcpy(parentIdTag, sstr);
  8440. }
  8441. else
  8442. {
  8443. strcpy(parentIdTag, "");
  8444. }
  8445. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8446. //Search "status"
  8447. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8448. loc = strstr(CardList[c], "status");
  8449. j = 0;
  8450. while (loc[3+strlen("status")+j] != '\"')
  8451. {
  8452. sstr[j] = loc[3+strlen("status")+j];
  8453. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8454. j++;
  8455. }
  8456. sstr[j] = '\0';
  8457. strcpy(idTagstatus, sstr);
  8458. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8459. OCPP_getIdTag(idTagstr);
  8460. //OCPP_getIdTag("test"); For Test
  8461. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8462. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8463. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8464. {
  8465. //Local list full update
  8466. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8467. // update list
  8468. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8469. //DEBUG_INFO("Local list full update. 1\n");
  8470. //OCPP_get_TableAuthlocalAllData();
  8471. //DEBUG_INFO("Local list full update. 2\n");
  8472. }
  8473. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8474. {
  8475. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8476. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8477. }
  8478. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8479. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8480. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8481. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8482. c++;
  8483. }
  8484. }
  8485. else
  8486. {
  8487. //Check UpdateType
  8488. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8489. {
  8490. //Local list full update
  8491. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8492. OCPP_cleanLocalList();
  8493. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8494. goto end;
  8495. }
  8496. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8497. {
  8498. //Local list different update
  8499. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8500. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8501. goto end;
  8502. }
  8503. }
  8504. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8505. end:
  8506. sendSendLocalListConfirmation(uuid, comfirmstr);
  8507. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8508. return result;
  8509. }
  8510. #define MAX 200
  8511. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8512. {
  8513. mtrace();
  8514. int result = FAIL;
  8515. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8516. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8517. char chargingProfilePurposeStr[30]={0};
  8518. char chargingProfileKindStr[16]={0};
  8519. char recurrencyKindStr[10]={0};
  8520. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8521. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8522. int chargingSchedulePeriodCount = 0;
  8523. char comfirmstr[20]={0};
  8524. int meet= FALSE;
  8525. FILE *fptr1;
  8526. char filename[MAX]={0};
  8527. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8528. char rmFileCmd[50]={0};
  8529. char tempchargingProfilePurposeStr[30]={0};
  8530. char word[1600]={0};
  8531. int n_chargingProfile = 0;
  8532. json_object *SetChargingProfile;
  8533. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8534. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8535. SetChargingProfile = json_tokener_parse(payload);
  8536. if(!is_error(SetChargingProfile))
  8537. {
  8538. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8539. {
  8540. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8541. if(connectorIdInt == 0)
  8542. {
  8543. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8544. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8545. }
  8546. else
  8547. {
  8548. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8549. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8550. }
  8551. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8552. }
  8553. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8554. {
  8555. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8556. {
  8557. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8558. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8561. }
  8562. else
  8563. {
  8564. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8565. }
  8566. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8567. }
  8568. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8569. {
  8570. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8571. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8572. {
  8573. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8574. }
  8575. else
  8576. {
  8577. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8578. }
  8579. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8580. }
  8581. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8582. {
  8583. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8585. {
  8586. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8587. }
  8588. else
  8589. {
  8590. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8591. }
  8592. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8593. }
  8594. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8595. {
  8596. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8597. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8598. {
  8599. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8600. }
  8601. else
  8602. {
  8603. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8604. }
  8605. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8606. }
  8607. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8608. {
  8609. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8610. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8611. {
  8612. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8613. }
  8614. else
  8615. {
  8616. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8617. }
  8618. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8619. }
  8620. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8621. {
  8622. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8623. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8624. {
  8625. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8626. }
  8627. else
  8628. {
  8629. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8630. }
  8631. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8632. }
  8633. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8634. {
  8635. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8636. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8637. {
  8638. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8639. }
  8640. else
  8641. {
  8642. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8643. }
  8644. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8645. }
  8646. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8647. {
  8648. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8649. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8650. {
  8651. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8652. }
  8653. else
  8654. {
  8655. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8656. }
  8657. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8658. }
  8659. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8660. {
  8661. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8662. {
  8663. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8665. {
  8666. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8667. }
  8668. else
  8669. {
  8670. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8671. }
  8672. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8673. }
  8674. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8675. {
  8676. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8678. {
  8679. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8680. }
  8681. else
  8682. {
  8683. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8684. }
  8685. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8686. }
  8687. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8688. {
  8689. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8690. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8691. {
  8692. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8693. }
  8694. else
  8695. {
  8696. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8697. }
  8698. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8699. }
  8700. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8701. {
  8702. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8703. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8704. {
  8705. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8706. }
  8707. else
  8708. {
  8709. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8710. }
  8711. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8712. }
  8713. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8714. {
  8715. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8716. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8717. if(chargingSchedulePeriodCount <= 10)
  8718. {
  8719. 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++)
  8720. {
  8721. 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)
  8722. {
  8723. 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"));
  8724. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8725. {
  8726. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8727. }
  8728. else
  8729. {
  8730. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8731. }
  8732. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8733. }
  8734. 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)
  8735. {
  8736. 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"));
  8737. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8738. {
  8739. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8740. }
  8741. else
  8742. {
  8743. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8744. }
  8745. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8746. }
  8747. 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)
  8748. {
  8749. 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"));
  8750. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8751. {
  8752. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8753. }
  8754. else
  8755. {
  8756. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8757. }
  8758. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8759. }
  8760. }
  8761. }
  8762. }
  8763. }
  8764. }
  8765. }
  8766. json_object_put(SetChargingProfile);
  8767. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8768. {
  8769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8770. goto end;
  8771. }
  8772. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8773. {
  8774. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8775. if(connectorIdInt != 0)
  8776. {
  8777. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8778. goto end;
  8779. }
  8780. strcpy(filename, ChargePointMaxProfile_JSON );
  8781. fptr1 = fopen(filename, "r");
  8782. if (!fptr1)
  8783. {
  8784. //file not exist
  8785. DEBUG_INFO("Unable to open the input file!!\n");
  8786. fptr1 = fopen(filename, "w+");
  8787. }
  8788. else
  8789. {
  8790. //Check Charging Profile Count
  8791. while(fscanf(fptr1, "%s", word) != EOF)
  8792. {
  8793. //DEBUG_INFO("word=%s\n",word);
  8794. if(strstr(word, "chargingProfileId")!= NULL)
  8795. {
  8796. //DEBUG_INFO("test chargingProfileId \n");
  8797. n_chargingProfile = n_chargingProfile + 1;
  8798. //DEBUG_INFO("chargingProfileId Found\n");
  8799. }
  8800. }
  8801. }
  8802. fclose(fptr1);
  8803. }
  8804. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8805. {
  8806. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8807. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8808. {
  8809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8810. goto end;
  8811. }
  8812. memset(filename, 0, ARRAY_SIZE(filename));
  8813. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8814. fptr1 = fopen(filename, "r");
  8815. if (!fptr1)
  8816. {
  8817. //file not exist
  8818. //DEBUG_INFO("Unable to open the input file!!\n");
  8819. fptr1 = fopen(filename, "w+");
  8820. }
  8821. else
  8822. {
  8823. //Check Charging Profile Count
  8824. while(fscanf(fptr1, "%s", word) != EOF)
  8825. {
  8826. //DEBUG_INFO("word=%s\n",word);
  8827. if(strstr(word, "chargingProfileId")!= NULL)
  8828. {
  8829. //DEBUG_INFO("test chargingProfileId \n");
  8830. n_chargingProfile = n_chargingProfile + 1;
  8831. //DEBUG_INFO("chargingProfileId Found\n");
  8832. }
  8833. }
  8834. }
  8835. fclose(fptr1);
  8836. }
  8837. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8838. {
  8839. //printf("set chargingProfile 1-4\n");
  8840. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8841. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8842. if(connectorIdInt == 0)
  8843. {
  8844. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8845. goto end;
  8846. }
  8847. int tempIndex = 0;
  8848. //check Transaction active
  8849. if(gunType[connectorIdInt -1] == 'J')
  8850. {
  8851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8852. {
  8853. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8854. }
  8855. else
  8856. {
  8857. tempIndex = connectorIdInt -1;
  8858. }
  8859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8860. {
  8861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8862. {
  8863. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8864. {
  8865. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8866. {
  8867. meet = TRUE;
  8868. break;
  8869. }
  8870. }
  8871. }
  8872. }
  8873. }
  8874. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8875. {
  8876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8877. {
  8878. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8879. }
  8880. else
  8881. {
  8882. tempIndex = connectorIdInt -1;
  8883. }
  8884. for (int index = 0; index < CCS_QUANTITY; index++)
  8885. {
  8886. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8887. {
  8888. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8889. {
  8890. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8891. {
  8892. meet = TRUE;
  8893. break;
  8894. }
  8895. }
  8896. }
  8897. }
  8898. }
  8899. else if(gunType[connectorIdInt -1] == 'G')
  8900. {
  8901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8902. {
  8903. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8904. }
  8905. else
  8906. {
  8907. tempIndex = connectorIdInt -1;
  8908. }
  8909. for (int index = 0; index < GB_QUANTITY; index++)
  8910. {
  8911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8912. {
  8913. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8914. {
  8915. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8916. {
  8917. meet = TRUE;
  8918. break;
  8919. }
  8920. }
  8921. }
  8922. }
  8923. }
  8924. else if(gunType[connectorIdInt -1] == 'O')
  8925. {
  8926. tempIndex = connectorIdInt -1;
  8927. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8928. {
  8929. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8930. {
  8931. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8932. {
  8933. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8934. {
  8935. meet = TRUE;
  8936. break;
  8937. }
  8938. }
  8939. }
  8940. }
  8941. }
  8942. else
  8943. {
  8944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8945. {
  8946. tempIndex = 2;
  8947. }
  8948. else
  8949. {
  8950. tempIndex = (connectorIdInt -1);
  8951. }
  8952. for (int index = 0; index < AC_QUANTITY; index++)
  8953. {
  8954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8955. {
  8956. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8957. {
  8958. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8959. {
  8960. meet = TRUE;
  8961. break;
  8962. }
  8963. }
  8964. }
  8965. }
  8966. }
  8967. //check Transaction active
  8968. if(meet == FALSE)
  8969. {
  8970. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8971. goto end;
  8972. }
  8973. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8974. {
  8975. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8976. goto end;
  8977. }
  8978. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8979. fptr1 = fopen(filename, "r");
  8980. if (!fptr1)
  8981. {
  8982. //file not exist
  8983. DEBUG_INFO("Unable to open the input file!!\n");
  8984. fptr1 = fopen(filename, "w+");
  8985. }
  8986. else
  8987. {
  8988. //Check Charging Profile Count
  8989. while(fscanf(fptr1, "%s", word) != EOF)
  8990. {
  8991. //DEBUG_INFO("word=%s\n",word);
  8992. if(strstr(word, "chargingProfileId")!= NULL)
  8993. {
  8994. //DEBUG_INFO("test chargingProfileId \n");
  8995. n_chargingProfile = n_chargingProfile + 1;
  8996. //DEBUG_INFO("chargingProfileId Found\n");
  8997. }
  8998. }
  8999. }
  9000. fclose(fptr1);
  9001. }
  9002. // Check ChargeProfileMaxStackLevel
  9003. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9004. {
  9005. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9006. goto end;
  9007. }
  9008. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9009. {
  9010. int i = 0;
  9011. char fnametemp[200]={0};
  9012. n_chargingProfile = 0;
  9013. //Check ChargePointMaxProfile.json exit
  9014. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9015. {
  9016. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9017. //Check Charging Profile Count
  9018. while(fscanf(fptr1, "%s", word) != EOF)
  9019. {
  9020. //DEBUG_INFO("word=%s\n",word);
  9021. if(strstr(word, "chargingProfileId")!= NULL)
  9022. {
  9023. //DEBUG_INFO("test chargingProfileId \n");
  9024. n_chargingProfile = n_chargingProfile + 1;
  9025. i = i + 1;
  9026. //DEBUG_INFO("chargingProfileId Found\n");
  9027. }
  9028. memset(word, 0, ARRAY_SIZE(word));
  9029. }
  9030. fclose(fptr1);
  9031. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9032. }
  9033. //Check TxDefaultProfile_0.json exit
  9034. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9035. {
  9036. i = 0;
  9037. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9038. //Check Charging Profile Count
  9039. while(fscanf(fptr1, "%s", word) != EOF)
  9040. {
  9041. //DEBUG_INFO("word=%s\n",word);
  9042. if(strstr(word, "chargingProfileId")!= NULL)
  9043. {
  9044. //DEBUG_INFO("test chargingProfileId \n");
  9045. n_chargingProfile = n_chargingProfile + 1;
  9046. i = i + 1;
  9047. //DEBUG_INFO("chargingProfileId Found\n");
  9048. }
  9049. memset(word, 0, ARRAY_SIZE(word));
  9050. }
  9051. fclose(fptr1);
  9052. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9053. }
  9054. //Check TxDefaultProfile_%d.json
  9055. for(int j=1; j <= gunTotalNumber; j++)
  9056. {
  9057. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9058. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9059. if((access(fnametemp,F_OK))!=-1)
  9060. {
  9061. i = 0;
  9062. fptr1 = fopen(fnametemp, "r");
  9063. //Check Charging Profile Count
  9064. while(fscanf(fptr1, "%s", word) != EOF)
  9065. {
  9066. //DEBUG_INFO("word=%s\n",word);
  9067. if(strstr(word, "chargingProfileId")!= NULL)
  9068. {
  9069. //DEBUG_INFO("test chargingProfileId \n");
  9070. n_chargingProfile = n_chargingProfile + 1;
  9071. i = i + 1;
  9072. //DEBUG_INFO("chargingProfileId Found\n");
  9073. }
  9074. memset(word, 0, ARRAY_SIZE(word));
  9075. }
  9076. fclose(fptr1);
  9077. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9078. }
  9079. }
  9080. //Check TxProfile_%d.json
  9081. for(int j=1; j <= gunTotalNumber; j++)
  9082. {
  9083. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9084. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9085. if((access(fnametemp,F_OK))!=-1)
  9086. {
  9087. i = 0;
  9088. fptr1 = fopen(fnametemp, "r");
  9089. //Check Charging Profile Count
  9090. while(fscanf(fptr1, "%s", word) != EOF)
  9091. {
  9092. //DEBUG_INFO("word=%s\n",word);
  9093. if(strstr(word, "chargingProfileId")!= NULL)
  9094. {
  9095. //DEBUG_INFO("test chargingProfileId \n");
  9096. n_chargingProfile = n_chargingProfile + 1;
  9097. i = i + 1;
  9098. //DEBUG_INFO("chargingProfileId Found\n");
  9099. }
  9100. memset(word, 0, ARRAY_SIZE(word));
  9101. }
  9102. fclose(fptr1);
  9103. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9104. }
  9105. }
  9106. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9107. {
  9108. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9109. goto end;
  9110. }
  9111. }
  9112. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9113. //**********************************Write to File********************************************************/
  9114. FILE *infile;
  9115. FILE *outfile;
  9116. infile = fopen (filename, "r");
  9117. outfile = fopen (tempfile, "w");
  9118. int d =0;
  9119. d = fgetc(infile);
  9120. rewind(infile);
  9121. if(d == EOF)
  9122. {
  9123. // Profile is empty
  9124. fprintf(outfile,"%s\n",payload);
  9125. fclose(infile);
  9126. fclose(outfile);
  9127. sprintf(rmFileCmd,"rm -f %s",filename);
  9128. system(rmFileCmd);
  9129. rename(tempfile, filename);
  9130. }
  9131. else
  9132. {
  9133. // Profile is not empty
  9134. char buf[2048]={0};
  9135. int ChargingProfileAdded = FALSE;
  9136. while (fgets(buf, sizeof(buf), infile) != NULL)
  9137. {
  9138. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9139. json_object *tmpChargingProfile;
  9140. tmpChargingProfile = json_tokener_parse(buf);
  9141. if(!is_error(SetChargingProfile))
  9142. {
  9143. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9144. {
  9145. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9146. }
  9147. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9148. {
  9149. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9150. {
  9151. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9152. }
  9153. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9154. {
  9155. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9156. }
  9157. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9158. {
  9159. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9160. }
  9161. }
  9162. }
  9163. json_object_put(tmpChargingProfile);
  9164. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9165. {
  9166. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9167. {
  9168. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9169. if(ChargingProfileAdded == FALSE)
  9170. {
  9171. fprintf(outfile,"%s\n",payload);
  9172. ChargingProfileAdded = TRUE;
  9173. }
  9174. }
  9175. else
  9176. {
  9177. if(tempstackLevelInt < stackLevelInt)
  9178. {
  9179. if(ChargingProfileAdded == FALSE)
  9180. {
  9181. fprintf(outfile,"%s\n",buf);
  9182. fprintf(outfile,"%s\n",payload);
  9183. ChargingProfileAdded = TRUE;
  9184. }
  9185. else
  9186. {
  9187. fprintf(outfile,"%s\n",buf);
  9188. }
  9189. }
  9190. else
  9191. {
  9192. if(ChargingProfileAdded == FALSE)
  9193. {
  9194. fprintf(outfile,"%s\n",buf);
  9195. fprintf(outfile,"%s\n",payload);
  9196. ChargingProfileAdded = TRUE;
  9197. }
  9198. else
  9199. {
  9200. fprintf(outfile,"%s\n",buf);
  9201. }
  9202. }
  9203. }
  9204. }
  9205. else
  9206. {
  9207. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9208. {
  9209. if(ChargingProfileAdded == FALSE)
  9210. {
  9211. fprintf(outfile,"%s\n",buf);
  9212. fprintf(outfile,"%s\n",payload);
  9213. ChargingProfileAdded = TRUE;
  9214. }
  9215. else
  9216. {
  9217. fprintf(outfile,"%s\n",buf);
  9218. }
  9219. }
  9220. else if(tempstackLevelInt < stackLevelInt)
  9221. {
  9222. if(ChargingProfileAdded == FALSE)
  9223. {
  9224. fprintf(outfile,"%s\n",buf);
  9225. fprintf(outfile,"%s\n",payload);
  9226. ChargingProfileAdded = TRUE;
  9227. }
  9228. else
  9229. {
  9230. fprintf(outfile,"%s\n",buf);
  9231. }
  9232. }
  9233. else
  9234. {
  9235. if(ChargingProfileAdded == FALSE)
  9236. {
  9237. fprintf(outfile,"%s\n",buf);
  9238. fprintf(outfile,"%s\n",payload);
  9239. ChargingProfileAdded = TRUE;
  9240. }
  9241. else
  9242. {
  9243. fprintf(outfile,"%s\n",buf);
  9244. }
  9245. }
  9246. }
  9247. } // end of while loop
  9248. fclose(infile);
  9249. fclose(outfile);
  9250. sprintf(rmFileCmd,"rm -f %s",filename);
  9251. system(rmFileCmd);
  9252. rename(tempfile, filename);
  9253. }
  9254. sleep(1);
  9255. result = TRUE;
  9256. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9257. end:
  9258. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9259. return result;
  9260. }
  9261. int handleTriggerMessageRequest(char *uuid, char *payload)
  9262. {
  9263. mtrace();
  9264. int result = FAIL;
  9265. int connectorIdIsNULL = FALSE;
  9266. int connectorIdInt =0;
  9267. char sstr[40]={0},sstrtemp[100]={ 0 };
  9268. char requestedMessagestr[40]={0};
  9269. char comfirmstr[20]={0};
  9270. int c = 0;
  9271. char *loc;
  9272. DEBUG_INFO("handleTriggerMessageRequest\n");
  9273. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9274. strcpy(sstrtemp, stringtrimspace(payload));
  9275. c = 0;
  9276. loc = strstr(sstrtemp, "requestedMessage");
  9277. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9278. {
  9279. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9280. c++;
  9281. }
  9282. sstr[c] = '\0';
  9283. strcpy(requestedMessagestr, sstr);
  9284. c = 0;
  9285. loc = strstr(sstrtemp, "connectorId");
  9286. if(loc == NULL)
  9287. {
  9288. connectorIdIsNULL = TRUE;
  9289. }
  9290. else
  9291. {
  9292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9293. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9294. {
  9295. sstr[c] = loc[strlen("connectorId")+2+c];
  9296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9297. c++;
  9298. }
  9299. sstr[c] = '\0';
  9300. connectorIdInt = atoi(sstr);
  9301. }
  9302. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9303. {
  9304. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9305. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9306. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9307. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9308. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9309. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9310. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9311. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9312. {
  9313. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9314. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9315. return TRUE;
  9316. }
  9317. else
  9318. {
  9319. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9320. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9321. }
  9322. }
  9323. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9324. {
  9325. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9326. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9327. return TRUE;
  9328. }
  9329. //==========================
  9330. // Trigger message
  9331. //==========================
  9332. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9333. {
  9334. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9335. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9336. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9337. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9338. {
  9339. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9340. }
  9341. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9342. }
  9343. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9344. {
  9345. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9346. }
  9347. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9348. {
  9349. //sendBootNotificationRequest();
  9350. server_sign = FALSE;
  9351. }
  9352. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9353. {
  9354. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9355. }
  9356. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9357. {
  9358. if(connectorIdIsNULL == FALSE)
  9359. {
  9360. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9361. {
  9362. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9363. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9364. }
  9365. }
  9366. else
  9367. {
  9368. for(int idx=0;idx< gunTotalNumber;idx++)
  9369. {
  9370. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9371. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9372. }
  9373. }
  9374. }
  9375. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9376. {
  9377. if(connectorIdIsNULL == FALSE)
  9378. {
  9379. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9380. {
  9381. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9382. }
  9383. }
  9384. else
  9385. {
  9386. for(int idx=0;idx< gunTotalNumber;idx++)
  9387. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9388. }
  9389. }
  9390. return result;
  9391. }
  9392. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9393. {
  9394. mtrace();
  9395. int result = FAIL;
  9396. int connectorIdInt =0;
  9397. char comfirmstr[20]={0};
  9398. int tempIndex = 0;
  9399. json_object *UnlockConnector;
  9400. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9401. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9402. UnlockConnector = json_tokener_parse(payload);
  9403. if(!is_error(UnlockConnector))
  9404. {
  9405. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9406. {
  9407. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9408. }
  9409. }
  9410. json_object_put(UnlockConnector);
  9411. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9412. if(gunTotalNumber == 0)
  9413. {
  9414. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9415. goto end;
  9416. }
  9417. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9418. {
  9419. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9420. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9421. goto end;
  9422. }
  9423. else
  9424. {
  9425. //check Transaction active
  9426. if(gunType[connectorIdInt-1] == 'J')
  9427. {
  9428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9429. {
  9430. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9431. }
  9432. else
  9433. {
  9434. tempIndex = connectorIdInt -1;
  9435. }
  9436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9437. {
  9438. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9439. {
  9440. //stop Transaction
  9441. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9442. }
  9443. }
  9444. }
  9445. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9446. {
  9447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9448. {
  9449. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9450. }
  9451. else
  9452. {
  9453. tempIndex = connectorIdInt -1;
  9454. }
  9455. for (int index = 0; index < CCS_QUANTITY; index++)
  9456. {
  9457. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9458. {
  9459. //stop Transaction
  9460. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9461. }
  9462. }
  9463. }
  9464. else if(gunType[connectorIdInt-1] == 'G')
  9465. {
  9466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9467. {
  9468. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9469. }
  9470. else
  9471. {
  9472. tempIndex = connectorIdInt -1;
  9473. }
  9474. for (int index = 0; index < GB_QUANTITY; index++)
  9475. {
  9476. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9477. {
  9478. //stop Transaction
  9479. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9480. }
  9481. }
  9482. }
  9483. else if(gunType[connectorIdInt-1] == 'O')
  9484. {
  9485. tempIndex = connectorIdInt -1;
  9486. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9487. {
  9488. 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)))
  9489. {
  9490. //stop Transaction
  9491. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9492. }
  9493. }
  9494. }
  9495. else
  9496. {
  9497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9498. {
  9499. tempIndex = 2;
  9500. }
  9501. else
  9502. {
  9503. tempIndex = connectorIdInt-1;
  9504. }
  9505. for (int index = 0; index < AC_QUANTITY; index++)
  9506. {
  9507. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9508. {
  9509. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9510. }
  9511. }
  9512. }
  9513. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9514. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9515. result = TRUE;
  9516. return result;
  9517. }
  9518. end:
  9519. //json_object_put(obj); --- remove temporally
  9520. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9521. return result;
  9522. }
  9523. static char UpdateFirmwarepayloadData[300]={0};
  9524. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9525. {
  9526. mtrace();
  9527. int result = FAIL;
  9528. pthread_t t;
  9529. sendUpdateFirmwareConfirmation(uuid);
  9530. memset(UpdateFirmwarepayloadData, 0, 300);
  9531. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9532. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9533. ////pthread_join(t, NULL); //
  9534. //pthread_detach(t);
  9535. //sendUpdateFirmwareConfirmation(uuid);
  9536. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9537. return result;
  9538. }
  9539. void *UpdateFirmwareProcess(void *data)
  9540. {
  9541. pthread_detach(pthread_self());
  9542. mtrace();
  9543. int retriesInt =0, retryIntervalInt=0;
  9544. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9545. int port=0;
  9546. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9547. int isSuccess = 0;
  9548. char ftpbuf[200];
  9549. char temp[100];
  9550. char * pch;
  9551. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9552. json_object *UpdateFirmware;
  9553. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9554. if(!is_error(UpdateFirmware))
  9555. {
  9556. // Required data
  9557. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9558. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9559. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9560. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9561. // Optional data
  9562. if(json_object_object_get(UpdateFirmware, "retries"))
  9563. {
  9564. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9565. }
  9566. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9567. {
  9568. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9569. }
  9570. }
  9571. json_object_put(UpdateFirmware);
  9572. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9573. memset(path, 0, ARRAY_SIZE(path));
  9574. system("rm -f /mnt/*");
  9575. if(strncmp(locationstr,"http", 4) == 0)
  9576. {
  9577. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9578. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9579. // protocol, user, password, host, path);
  9580. sprintf(ftppath,"/%s", path);
  9581. DEBUG_INFO("locationstr: %s\n", locationstr);
  9582. DEBUG_INFO("protocol: %s\n",protocol);
  9583. DEBUG_INFO("host: %s\n",host);
  9584. DEBUG_INFO("path: %s\n",path);
  9585. DEBUG_INFO("ftppath: %s\n",ftppath);
  9586. int ftppathlen=strlen(ftppath);
  9587. int i=1;
  9588. char filenametemp[50];
  9589. while(i < ftppathlen)
  9590. {
  9591. int len=ftppathlen-i;
  9592. if(ftppath[len]== 47) // '/' ascll code: 47
  9593. {
  9594. DEBUG_INFO("compare '/' all right\n");
  9595. break;
  9596. }
  9597. i=i+1;
  9598. }
  9599. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9600. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9601. filenametemp[i+1] = 0;
  9602. do
  9603. {
  9604. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9605. sleep(3);
  9606. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9607. if(!isSuccess)
  9608. {
  9609. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9610. sleep(retryIntervalInt);
  9611. }
  9612. else
  9613. {
  9614. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9615. }
  9616. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9617. }
  9618. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9619. {
  9620. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9621. memset(temp, 0, ARRAY_SIZE(temp));
  9622. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9623. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9624. int ftppathlen=strlen(ftpbuf);
  9625. int i=1;
  9626. char filenametemp[50];
  9627. while(i < ftppathlen)
  9628. {
  9629. int len=ftppathlen-i;
  9630. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9631. {
  9632. DEBUG_INFO(" compare '/' all right\n");
  9633. break;
  9634. }
  9635. i=i+1;
  9636. }
  9637. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9638. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9639. filenametemp[i+1] = 0;
  9640. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9641. pch=strchr(temp,'@');
  9642. if(pch==NULL)
  9643. {
  9644. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9645. protocol, host, &port, path);
  9646. strcpy(user,"anonymous");
  9647. strcpy(password,"");
  9648. }
  9649. else
  9650. {
  9651. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9652. protocol, user, password, host, &port, path);
  9653. }
  9654. sscanf(host,"%[^/]%s",host1, path1);
  9655. sprintf(ftppath,"%s", path1);
  9656. //DEBUG_INFO("protocol =%s\n",protocol);
  9657. //DEBUG_INFO("user =%s\n",user);
  9658. //DEBUG_INFO("password =%s\n",password);
  9659. //DEBUG_INFO("host1 =%s\n",host1);
  9660. //DEBUG_INFO("port =%d\n",port);
  9661. //DEBUG_INFO("path1 =%s\n",path1);
  9662. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9663. //ftpFile(host, user, password, port, ftppath, fname);
  9664. //download firmware pthred
  9665. if(port == 0)
  9666. {
  9667. port = 21;
  9668. }
  9669. do
  9670. {
  9671. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9672. sleep(3);
  9673. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9674. if(!isSuccess)
  9675. {
  9676. //BulldogUtil.sleepMs(interval*1000);
  9677. DEBUG_INFO("Update firmware request and download file fail.\n");
  9678. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9679. sleep(retryIntervalInt);
  9680. }
  9681. else
  9682. {
  9683. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9684. }
  9685. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9686. }
  9687. else
  9688. {
  9689. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9690. }
  9691. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9692. pthread_exit(NULL);
  9693. }
  9694. //==========================================
  9695. // Handle server response routine
  9696. //==========================================
  9697. void handleAuthorizeResponse(char *payload, int gun_index)
  9698. {
  9699. mtrace();
  9700. char expiryDatestr[30]={0};
  9701. char parentIdTagstr[20]={0};
  9702. char statusstr[20]={0};
  9703. char expiryDatestrtemp[30]={0};
  9704. char parentIdTagstrtemp[20]={0};
  9705. char IdTagstrtemp[20]={0};
  9706. char statusstrtemp[20]={0};
  9707. int expiryDateISNULL=FALSE;
  9708. int parentIdTagISNULL=FALSE;
  9709. char sstr[160]={0};
  9710. char* filename = AuthorizationCache_JSON;
  9711. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9712. char *loc;
  9713. int resultRename=0;
  9714. int responseIdTagInfoAsZero= 0;
  9715. char rmFileCmd[50]={0};
  9716. DEBUG_INFO("handleAuthorizeResponse...\n");
  9717. json_object *Authorize;
  9718. Authorize = json_tokener_parse(payload);
  9719. if(!is_error(Authorize))
  9720. {
  9721. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9722. {
  9723. // Required data
  9724. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9725. // Optional data
  9726. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9727. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9728. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9729. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9730. }
  9731. }
  9732. json_object_put(Authorize);
  9733. if(expiryDateISNULL == FALSE)
  9734. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9735. if(parentIdTagISNULL == FALSE)
  9736. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9737. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9738. //Update idTag information to authorization cache if supproted
  9739. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9740. {
  9741. if((access(filename,F_OK))!=-1)
  9742. {
  9743. printf("AuthorizationCache exist.\n");
  9744. }
  9745. else
  9746. {
  9747. printf("AuthorizationCache not exist\n");
  9748. FILE *log = fopen(filename, "w+");
  9749. if(log == NULL)
  9750. {
  9751. printf("log is NULL\n");
  9752. goto out;
  9753. }
  9754. else
  9755. {
  9756. fclose(log);
  9757. }
  9758. }
  9759. FILE *infile;
  9760. FILE *outfile;
  9761. // open file for writing
  9762. infile = fopen (filename, "r");
  9763. outfile = fopen (tempfile, "w");
  9764. int c;
  9765. c = fgetc(infile);
  9766. //DEBUG_INFO("c:%d\n",c);
  9767. rewind(infile);
  9768. if(c == EOF)
  9769. {
  9770. DEBUG_INFO("Orignal File is NULL\n");
  9771. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9772. {
  9773. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9774. }
  9775. else
  9776. {
  9777. strcpy(expiryDatestrtemp, "");
  9778. }
  9779. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9780. {
  9781. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9782. }
  9783. else
  9784. {
  9785. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9786. }
  9787. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9788. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9789. fclose(infile);
  9790. fclose(outfile);
  9791. sprintf(rmFileCmd,"rm -f %s",filename);
  9792. system(rmFileCmd);
  9793. resultRename = rename(tempfile, filename);
  9794. if(resultRename == 0)
  9795. {
  9796. printf("File renamed successfully");
  9797. }
  9798. else
  9799. {
  9800. printf("Error: unable to rename the file");
  9801. }
  9802. }
  9803. else
  9804. {
  9805. char buf[160]={0};
  9806. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9807. {
  9808. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9809. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9810. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9811. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9812. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9813. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9814. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9815. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9816. //------------------IdTag-----------------------
  9817. loc = strstr(buf, "idTag");
  9818. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9819. c = 0;
  9820. while (loc[3+strlen("idTag")+c] != '\"')
  9821. {
  9822. sstr[c] = loc[3+strlen("idTag")+c];
  9823. c++;
  9824. }
  9825. sstr[c] = '\0';
  9826. strcpy(IdTagstrtemp,sstr);
  9827. //*********************expiryDate***************/
  9828. loc = strstr(buf, "expiryDate");
  9829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9830. c = 0;
  9831. while (loc[3+strlen("expiryDate")+c] != '\"')
  9832. {
  9833. sstr[c] = loc[3+strlen("expiryDate")+c];
  9834. c++;
  9835. }
  9836. sstr[c] = '\0';
  9837. strcpy(expiryDatestr,sstr);
  9838. //*********************parentIdTag***************/
  9839. loc = strstr(buf, "parentIdTag");
  9840. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9841. c = 0;
  9842. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9843. {
  9844. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9845. c++;
  9846. }
  9847. sstr[c] = '\0';
  9848. strcpy(parentIdTagstr,sstr);
  9849. //*********************status***************/
  9850. loc = strstr(buf, "status");
  9851. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9852. c = 0;
  9853. while (loc[3+strlen("status")+c] != '\"')
  9854. {
  9855. sstr[c] = loc[3+strlen("status")+c];
  9856. c++;
  9857. }
  9858. sstr[c] = '\0';
  9859. strcpy(statusstr,sstr);
  9860. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9861. {
  9862. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9863. responseIdTagInfoAsZero = 1;
  9864. }
  9865. else
  9866. {
  9867. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9868. }
  9869. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9870. {
  9871. //modify item
  9872. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9873. {
  9874. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9875. }
  9876. else
  9877. {
  9878. strcpy(expiryDatestrtemp, "");
  9879. }
  9880. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9881. {
  9882. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9883. }
  9884. else
  9885. {
  9886. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9887. }
  9888. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9889. }
  9890. else
  9891. {
  9892. //wrie original item
  9893. strcpy(expiryDatestrtemp, expiryDatestr);
  9894. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9895. strcpy(statusstrtemp, statusstr);
  9896. }
  9897. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9898. }
  9899. fclose(infile);
  9900. fclose(outfile);
  9901. sprintf(rmFileCmd,"rm -f %s",filename);
  9902. system(rmFileCmd);
  9903. resultRename = rename(tempfile, filename);
  9904. if(resultRename == 0)
  9905. {
  9906. DEBUG_INFO("File renamed successfully");
  9907. }
  9908. else
  9909. {
  9910. DEBUG_INFO("Error: unable to rename the file");
  9911. }
  9912. }
  9913. }
  9914. out:
  9915. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9916. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9917. authorizeRetryTimes = 0;
  9918. }
  9919. void handleBootNotificationResponse(char *payload, int gun_index)
  9920. {
  9921. mtrace();
  9922. char statusStr[12]={0};
  9923. char currentTimeStr[30]={0};
  9924. int intervalInt = 0;
  9925. struct tm tp;
  9926. char buf[28]={0};
  9927. char timebuf[50]={0};
  9928. DEBUG_INFO("handleBootNotificationResponse...\n");
  9929. json_object *BootNotification;
  9930. BootNotification = json_tokener_parse(payload);
  9931. if(!is_error(BootNotification))
  9932. {
  9933. // Required data
  9934. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9935. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9936. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9937. }
  9938. json_object_put(BootNotification);
  9939. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9940. BootNotificationInterval = intervalInt;
  9941. HeartBeatWaitTime = intervalInt;
  9942. //write back to ShmOCPP16Data->BootNotification
  9943. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9944. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9945. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9946. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9947. {
  9948. server_sign = TRUE;
  9949. server_pending =FALSE;
  9950. }
  9951. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9952. {
  9953. server_pending = TRUE;
  9954. }
  9955. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9956. tp.tm_isdst = -1;
  9957. //time_t utc = mktime(&tp);
  9958. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9959. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9960. sprintf(timebuf,"date -s '%s'",buf);
  9961. system(timebuf);
  9962. srand(time(NULL));
  9963. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9964. //==============================================
  9965. // RTC sync
  9966. //==============================================
  9967. system("/sbin/hwclock -w --systohc");
  9968. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9969. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9970. }
  9971. void handleDataTransferResponse(char *payload, int gun_index)
  9972. {
  9973. char sstr[160]={0};//sstr[200]={ 0 };
  9974. int c = 0;
  9975. char *loc;
  9976. DEBUG_INFO("handleDataTransferResponse ...\n");
  9977. loc = strstr(payload, "status");
  9978. printf("loc=%s\n",loc);
  9979. c = 0;
  9980. while (loc[3+strlen("status")+c] != '\"')
  9981. {
  9982. sstr[c] = loc[3+strlen("status")+c];
  9983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9984. c++;
  9985. }
  9986. sstr[c] = '\0';
  9987. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9988. }
  9989. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9990. {
  9991. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9992. //struct json_object *obj;
  9993. // obj = json_tokener_parse(payload);
  9994. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9995. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9996. //No fields are defined.
  9997. }
  9998. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9999. {
  10000. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10001. //struct json_object *obj;
  10002. // obj = json_tokener_parse(payload);
  10003. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10004. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10005. //No fields are defined.
  10006. }
  10007. void handleHeartbeatResponse(char *payload, int gun_index)
  10008. {
  10009. mtrace();
  10010. struct tm tp;
  10011. char buf[28]={0};
  10012. char timebuf[50]={0};
  10013. DEBUG_INFO("handleHeartbeatResponse...\n");
  10014. json_object *Heartbeat;
  10015. Heartbeat = json_tokener_parse(payload);
  10016. if(!is_error(Heartbeat))
  10017. {
  10018. // Required data
  10019. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10020. }
  10021. json_object_put(Heartbeat);
  10022. if(FirstHeartBeat == 0)
  10023. {
  10024. FirstHeartBeat = 1;
  10025. DEBUG_INFO("FirstHeartBeat \n");
  10026. }
  10027. HeartBeatWithNOResponse = 0;
  10028. clientTime.Heartbeat=time((time_t*)NULL);
  10029. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10030. tp.tm_isdst = -1;
  10031. //time_t utc = mktime(&tp);
  10032. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10033. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10034. sprintf(timebuf,"date -s '%s'",buf);
  10035. system(timebuf);
  10036. //==============================================
  10037. // RTC sync
  10038. //==============================================
  10039. system("/sbin/hwclock -w --systohc");
  10040. }
  10041. void handleMeterValuesResponse(char *payload, int gun_index)
  10042. {
  10043. mtrace();
  10044. DEBUG_INFO("handleMeterValuesResponse...\n");
  10045. }
  10046. void handleStartTransactionResponse(char *payload, int gun_index)
  10047. {
  10048. mtrace();
  10049. //int transactionIdInt = 0;
  10050. FILE *outfile;
  10051. char data[100]={0};
  10052. DEBUG_INFO("handleStartTransactionResponse...\n");
  10053. json_object *StartTransaction;
  10054. StartTransaction = json_tokener_parse(payload);
  10055. if(!is_error(StartTransaction))
  10056. {
  10057. // Required data
  10058. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10059. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10060. // Optional data
  10061. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10062. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10063. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10064. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10065. }
  10066. json_object_put(StartTransaction);
  10067. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10068. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10069. //-----------Start : write to the Queue TransactionId file -----------------//
  10070. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10071. {}
  10072. else
  10073. {
  10074. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10075. if(log == NULL)
  10076. {
  10077. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10078. return ;
  10079. }
  10080. else
  10081. {
  10082. fclose(log);
  10083. }
  10084. }
  10085. // open file for writing
  10086. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10087. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10088. {
  10089. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10090. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10091. fputs(data, outfile);
  10092. fclose (outfile);
  10093. }
  10094. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10095. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10096. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10097. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10098. }
  10099. void handleStatusNotificationResponse(char *payload, int gun_index)
  10100. {
  10101. mtrace();
  10102. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10103. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10104. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10105. }
  10106. void handleStopTransactionnResponse(char *payload, int gun_index)
  10107. {
  10108. mtrace();
  10109. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10110. json_object *StopTransaction;
  10111. StopTransaction = json_tokener_parse(payload);
  10112. if(!is_error(StopTransaction))
  10113. {
  10114. // Optional data
  10115. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10116. {
  10117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10118. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10120. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10122. }
  10123. }
  10124. json_object_put(StopTransaction);
  10125. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10126. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10127. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10128. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10129. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10130. }
  10131. //==========================================
  10132. // Handle Error routine
  10133. //==========================================
  10134. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10135. {
  10136. mtrace();
  10137. #ifdef SystemLogMessage
  10138. DEBUG_INFO("errorCode: %s\n", errorCode);
  10139. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10140. DEBUG_INFO("errorDetails: %s\n", payload);
  10141. #endif
  10142. }
  10143. //===============================================
  10144. // Common routine
  10145. //===============================================
  10146. int initialConfigurationTable(void)
  10147. {
  10148. //clock_t start_t, end_t, total_t;
  10149. FILE *fp;
  10150. FILE *outfile;
  10151. char str[200]={0};
  10152. char sstr[100]={0};
  10153. int c = 0;
  10154. char *loc;
  10155. DEBUG_INFO("initialConfigurationTable...\n");
  10156. //start_t = clock();
  10157. //printf("Starting of the program, start_t = %ld\n", start_t);
  10158. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10159. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10160. {
  10161. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10162. if(outfile == NULL)
  10163. {
  10164. DEBUG_INFO("Error opening file\n");
  10165. return FALSE;
  10166. }
  10167. /*Core Profile*/
  10168. //AllowOfflineTxForUnknownId
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10173. //AuthorizationCacheEnabled
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10178. //AuthorizeRemoteTxRequests
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10183. //BlinkRepeat
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10188. //ClockAlignedDataInterval
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10193. //ConnectionTimeOut
  10194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10198. //GetConfigurationMaxKeys
  10199. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10203. // HeartbeatInterval
  10204. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10208. // LightIntensity
  10209. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10213. // LocalAuthorizeOffline
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10218. // LocalPreAuthorize
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10223. // MaxEnergyOnInvalidId
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10227. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10229. // MeterValuesAlignedData
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10234. else
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10237. // MeterValuesAlignedDataMaxLength
  10238. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10242. else
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10245. // MeterValuesSampledData
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10250. else
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10253. // MeterValuesSampledDataMaxLength
  10254. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10258. else
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10261. // MeterValueSampleInterval
  10262. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10266. // MinimumStatusDuration
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10270. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10272. // NumberOfConnectors
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10276. {
  10277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10278. }
  10279. else
  10280. {
  10281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10282. }
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10284. // ResetRetries
  10285. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10289. // ConnectorPhaseRotation
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10294. // ConnectorPhaseRotationMaxLength
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10299. // StopTransactionOnEVSideDisconnect
  10300. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10304. // StopTransactionOnInvalidId
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10309. // StopTxnAlignedData
  10310. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10314. // StopTxnAlignedDataMaxLength
  10315. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10319. // StopTxnSampledData
  10320. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10324. else
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10327. // StopTxnSampledDataMaxLength
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10331. {
  10332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10333. }
  10334. else
  10335. {
  10336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10337. }
  10338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10339. // SupportedFeatureProfiles
  10340. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10344. // SupportedFeatureProfilesMaxLength
  10345. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10349. // TransactionMessageAttempts
  10350. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10353. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10355. // TransactionMessageRetryInterval
  10356. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10359. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10361. // UnlockConnectorOnEVSideDisconnect
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10366. // WebSocketPingInterval
  10367. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10371. // QueueOffLineStartTransactionMessage
  10372. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10376. // AuthorizationKey
  10377. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10381. // SecurityProfile
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10386. // DefaultPrice
  10387. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10391. // CustomDisplayCostAndPrice
  10392. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10396. // CustomIdleFeeAfterStop
  10397. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10401. //* Local Auth List Management Profile*/
  10402. #if 0
  10403. //For OCTT Test Case
  10404. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10407. #endif
  10408. #if 1
  10409. //LocalAuthListEnabled
  10410. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10414. #endif
  10415. //LocalAuthListMaxLength
  10416. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10420. //SendLocalListMaxLength
  10421. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10425. //ReserveConnectorZeroSupported
  10426. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10430. //* Smart Charging Profile */
  10431. //ChargeProfileMaxStackLevel
  10432. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10436. // ChargingScheduleAllowedChargingRateUnit
  10437. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10441. // ChargingScheduleMaxPeriods
  10442. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10446. // ConnectorSwitch3to1PhaseSupported
  10447. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10451. // MaxChargingProfilesInstalled
  10452. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "5" );
  10455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10456. fclose(outfile);
  10457. }
  10458. else
  10459. {
  10460. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10461. char keystr[60]={0};
  10462. char readonlystr[10]={0};
  10463. char valuestr[100]={0};
  10464. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10465. if(fp == NULL) {
  10466. DEBUG_INFO("Error opening file");
  10467. return FALSE;
  10468. }
  10469. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10470. {
  10471. //DEBUG_INFO("Get Configuration \n");
  10472. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10473. //*************************key*********************************/
  10474. loc = strstr(str, "key");
  10475. c = 0;
  10476. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10477. while (loc[strlen("key")+3+c] != '\"')
  10478. {
  10479. sstr[c] = loc[strlen("key")+3+c];
  10480. c++;
  10481. }
  10482. sstr[c] = '\0';
  10483. strcpy(keystr,sstr);
  10484. //*************************readonly*********************************/
  10485. loc = strstr(str, "readonly");
  10486. c = 0;
  10487. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10488. while (loc[strlen("readonly")+2+c] != ',')
  10489. {
  10490. sstr[c] = loc[strlen("readonly")+2+c];
  10491. c++;
  10492. }
  10493. sstr[c] = '\0';
  10494. strcpy(readonlystr,sstr);
  10495. //*************************value*********************************/
  10496. loc = strstr(str, "value");
  10497. c = 0;
  10498. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10499. while (loc[strlen("value")+3+c] != '\"')
  10500. {
  10501. sstr[c] = loc[strlen("value")+3+c];
  10502. c++;
  10503. }
  10504. sstr[c] = '\0';
  10505. strcpy(valuestr,sstr);
  10506. // DEBUG_INFO("keystr=%s\n",keystr);
  10507. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10508. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10509. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10510. {
  10511. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10514. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10515. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10516. }
  10517. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10518. {
  10519. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10522. }
  10523. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10527. }
  10528. if(strcmp(keystr, "BlinkRepeat") == 0)
  10529. {
  10530. //Charger.BlinkRepeat = Integer.parseInt(value);
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10533. }
  10534. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10538. }
  10539. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10543. }
  10544. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10548. }
  10549. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10553. HeartBeatWaitTime = atoi(valuestr);
  10554. }
  10555. if(strcmp(keystr, "LightIntensity") == 0)
  10556. {
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10559. }
  10560. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10561. {
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10564. }
  10565. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10566. {
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10569. }
  10570. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10571. {
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10574. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10575. }
  10576. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10577. {
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10580. }
  10581. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10582. {
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10585. }
  10586. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10590. }
  10591. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10595. }
  10596. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10600. }
  10601. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10605. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10606. }
  10607. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10611. }
  10612. if(strcmp(keystr, "ResetRetries") == 0)
  10613. {
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10616. }
  10617. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10618. {
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10621. }
  10622. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10623. {
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10626. }
  10627. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10628. {
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10631. }
  10632. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10636. }
  10637. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10641. }
  10642. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10646. }
  10647. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10651. }
  10652. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10656. }
  10657. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10661. }
  10662. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10663. {
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10666. }
  10667. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10668. {
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10671. TransactionMessageAttemptsValue = atoi(valuestr);
  10672. }
  10673. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10674. {
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10677. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10678. }
  10679. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10680. {
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10683. }
  10684. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10685. {
  10686. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10688. }
  10689. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10690. {
  10691. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10693. }
  10694. if(strcmp(keystr, "AuthorizationKey") == 0)
  10695. {
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10698. }
  10699. if(strcmp(keystr, "SecurityProfile") == 0)
  10700. {
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10703. }
  10704. if(strcmp(keystr, "DefaultPrice") == 0)
  10705. {
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10708. }
  10709. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10710. {
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10713. }
  10714. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10715. {
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10718. }
  10719. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10720. {
  10721. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10723. }
  10724. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10725. {
  10726. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10728. }
  10729. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10730. {
  10731. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10733. }
  10734. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10735. {
  10736. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10738. }
  10739. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10740. {
  10741. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10743. }
  10744. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10745. {
  10746. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10748. }
  10749. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10750. {
  10751. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10753. }
  10754. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10755. {
  10756. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10758. }
  10759. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10760. {
  10761. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10763. }
  10764. }
  10765. fclose(fp);
  10766. }
  10767. return 0;
  10768. }
  10769. void StoreConfigurationTable(void)
  10770. {
  10771. FILE *outfile;
  10772. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10773. if(outfile == NULL)
  10774. {
  10775. DEBUG_INFO("Error opening file");
  10776. return ;
  10777. }
  10778. /*Core Profile*/
  10779. //AllowOfflineTxForUnknownId
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10782. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10785. */
  10786. //DEBUG_INFO("data=%s\n",data);
  10787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10788. //AuthorizationCacheEnabled
  10789. /*
  10790. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10793. */
  10794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10795. //AuthorizeRemoteTxRequests
  10796. /*
  10797. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10800. */
  10801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10802. //BlinkRepeat
  10803. /*
  10804. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10807. */
  10808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10809. //ClockAlignedDataInterval
  10810. /*
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10814. */
  10815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10816. //ConnectionTimeOut
  10817. /*
  10818. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10821. */
  10822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10823. //GetConfigurationMaxKeys
  10824. /*
  10825. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10828. */
  10829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10830. // HeartbeatInterval
  10831. /*
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10835. */
  10836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10837. // LightIntensity
  10838. /*
  10839. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10842. */
  10843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10844. // LocalAuthorizeOffline
  10845. /*
  10846. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10849. */
  10850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10851. // LocalPreAuthorize
  10852. /*
  10853. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10856. */
  10857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10858. // MaxEnergyOnInvalidId
  10859. /*
  10860. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10863. */
  10864. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10866. // MeterValuesAlignedData
  10867. /*
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10871. */
  10872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10873. // MeterValuesAlignedDataMaxLength
  10874. /*
  10875. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10878. */
  10879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10880. // MeterValuesSampledData
  10881. /*
  10882. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10885. */
  10886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10887. // MeterValuesSampledDataMaxLength
  10888. /*
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10892. */
  10893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10894. // MeterValueSampleInterval
  10895. /*
  10896. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10899. */
  10900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10901. // MinimumStatusDuration
  10902. /*
  10903. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10906. */
  10907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10908. // NumberOfConnectors
  10909. /*
  10910. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10913. {
  10914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10915. }
  10916. else
  10917. {
  10918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10919. }
  10920. */
  10921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10922. // ResetRetries
  10923. /*
  10924. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10927. */
  10928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10929. // ConnectorPhaseRotation
  10930. /*
  10931. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10934. */
  10935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10936. // ConnectorPhaseRotationMaxLength
  10937. /*
  10938. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10941. */
  10942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10943. // StopTransactionOnEVSideDisconnect
  10944. /*
  10945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10948. */
  10949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10950. // StopTransactionOnInvalidId
  10951. /*
  10952. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10955. */
  10956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10957. // StopTxnAlignedData
  10958. /*
  10959. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10962. */
  10963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10964. // StopTxnAlignedDataMaxLength
  10965. /*
  10966. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10969. */
  10970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10971. // StopTxnSampledData
  10972. /*
  10973. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10976. */
  10977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10978. // StopTxnSampledDataMaxLength
  10979. /*
  10980. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10983. */
  10984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10985. // SupportedFeatureProfiles
  10986. /*
  10987. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10990. */
  10991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10992. // SupportedFeatureProfilesMaxLength
  10993. /*
  10994. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10997. */
  10998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10999. // TransactionMessageAttempts
  11000. /*
  11001. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11004. */
  11005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11006. // TransactionMessageRetryInterval
  11007. /*
  11008. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11011. */
  11012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11013. // UnlockConnectorOnEVSideDisconnect
  11014. /*
  11015. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11018. */
  11019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11020. // WebSocketPingInterval
  11021. /*
  11022. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11025. */
  11026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11027. // QueueOffLineStartTransactionMessage
  11028. /*
  11029. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11032. */
  11033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11034. // AuthorizationKey
  11035. /*
  11036. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11039. */
  11040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11041. // SecurityProfile
  11042. /*
  11043. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11046. */
  11047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11048. // DefaultPrice
  11049. /*
  11050. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11053. */
  11054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11055. // CustomDisplayCostAndPrice
  11056. /*
  11057. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11060. */
  11061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11062. // CustomIdleFeeAfterStop
  11063. /*
  11064. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11067. */
  11068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11069. //* Local Auth List Management Profile*/
  11070. //LocalAuthListEnabled
  11071. /*
  11072. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11075. */
  11076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11077. //LocalAuthListMaxLength
  11078. /*
  11079. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11082. */
  11083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11084. //SendLocalListMaxLength
  11085. /*
  11086. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11089. */
  11090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11091. //ReserveConnectorZeroSupported
  11092. /*
  11093. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11096. */
  11097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11098. //* Smart Charging Profile */
  11099. //ChargeProfileMaxStackLevel
  11100. /*
  11101. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11104. */
  11105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11106. // ChargingScheduleAllowedChargingRateUnit
  11107. /*
  11108. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11111. */
  11112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11113. // ChargingScheduleMaxPeriods
  11114. /*
  11115. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11118. */
  11119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11120. // ConnectorSwitch3to1PhaseSupported
  11121. /*
  11122. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11125. */
  11126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11127. // MaxChargingProfilesInstalled
  11128. /*
  11129. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11132. */
  11133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11134. fclose(outfile);
  11135. }
  11136. void getKeyValue(char *keyReq)
  11137. {
  11138. int isEmpty = FALSE;
  11139. int isKnowKey = FALSE;
  11140. DEBUG_INFO("keyReq = %s\n", keyReq);
  11141. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11142. isEmpty = TRUE;
  11143. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11150. }
  11151. else
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11154. }
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11156. isKnowKey = TRUE;
  11157. }
  11158. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11165. }
  11166. else
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11169. }
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11171. isKnowKey = TRUE;
  11172. }
  11173. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11180. }
  11181. else
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11184. }
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11186. isKnowKey = TRUE;
  11187. }
  11188. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11195. }
  11196. else
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11199. }
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11201. isKnowKey = TRUE;
  11202. }
  11203. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11210. }
  11211. else
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11214. }
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11216. isKnowKey = TRUE;
  11217. }
  11218. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11225. }
  11226. else
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11229. }
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11231. isKnowKey = TRUE;
  11232. }
  11233. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11240. }
  11241. else
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11244. }
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11246. isKnowKey = TRUE;
  11247. }
  11248. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11255. }
  11256. else
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11259. }
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11261. isKnowKey = TRUE;
  11262. }
  11263. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11270. }
  11271. else
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11274. }
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11276. isKnowKey = TRUE;
  11277. }
  11278. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11285. }
  11286. else
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11289. }
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11291. isKnowKey = TRUE;
  11292. }
  11293. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11300. }
  11301. else
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11304. }
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11306. isKnowKey = TRUE;
  11307. }
  11308. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11315. }
  11316. else
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11319. }
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11321. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11322. isKnowKey = TRUE;
  11323. }
  11324. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11331. }
  11332. else
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11335. }
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11337. isKnowKey = TRUE;
  11338. }
  11339. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11346. }
  11347. else
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11350. }
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11352. isKnowKey = TRUE;
  11353. }
  11354. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11361. }
  11362. else
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11365. }
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11367. isKnowKey = TRUE;
  11368. }
  11369. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11376. }
  11377. else
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11380. }
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11382. isKnowKey = TRUE;
  11383. }
  11384. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11391. }
  11392. else
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11395. }
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11397. isKnowKey = TRUE;
  11398. }
  11399. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11406. }
  11407. else
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11410. }
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11412. isKnowKey = TRUE;
  11413. }
  11414. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11421. }
  11422. else
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11425. }
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11427. isKnowKey = TRUE;
  11428. }
  11429. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11436. }
  11437. else
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11440. }
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11442. isKnowKey = TRUE;
  11443. }
  11444. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11451. }
  11452. else
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11455. }
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11457. isKnowKey = TRUE;
  11458. }
  11459. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11466. }
  11467. else
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11470. }
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11472. isKnowKey = TRUE;
  11473. }
  11474. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11481. }
  11482. else
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11485. }
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11487. isKnowKey = TRUE;
  11488. }
  11489. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11496. }
  11497. else
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11500. }
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11502. isKnowKey = TRUE;
  11503. }
  11504. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11505. {
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11511. }
  11512. else
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11515. }
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11517. isKnowKey = TRUE;
  11518. }
  11519. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11520. {
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11526. }
  11527. else
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11530. }
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11532. isKnowKey = TRUE;
  11533. }
  11534. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11541. }
  11542. else
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11545. }
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11547. isKnowKey = TRUE;
  11548. }
  11549. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11550. {
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11554. {
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11556. }
  11557. else
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11560. }
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11562. isKnowKey = TRUE;
  11563. }
  11564. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11565. {
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11569. {
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11571. }
  11572. else
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11575. }
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11577. isKnowKey = TRUE;
  11578. }
  11579. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11580. {
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11584. {
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11586. }
  11587. else
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11590. }
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11592. isKnowKey = TRUE;
  11593. }
  11594. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11595. {
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11599. {
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11601. }
  11602. else
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11605. }
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11607. isKnowKey = TRUE;
  11608. }
  11609. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11610. {
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11614. {
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11616. }
  11617. else
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11620. }
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11622. isKnowKey = TRUE;
  11623. }
  11624. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11625. {
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11631. }
  11632. else
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11635. }
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11637. isKnowKey = TRUE;
  11638. }
  11639. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11640. {
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11646. }
  11647. else
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11650. }
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11652. isKnowKey = TRUE;
  11653. }
  11654. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11661. }
  11662. else
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11665. }
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11667. isKnowKey = TRUE;
  11668. }
  11669. /*
  11670. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11677. }
  11678. else
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11681. }
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11683. isKnowKey = TRUE;
  11684. }*/
  11685. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11686. {
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11692. }
  11693. else
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11696. }
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11698. isKnowKey = TRUE;
  11699. }
  11700. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11707. }
  11708. else
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11711. }
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11713. isKnowKey = TRUE;
  11714. }
  11715. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11716. {
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11722. }
  11723. else
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11726. }
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11728. isKnowKey = TRUE;
  11729. }
  11730. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11731. {
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11737. }
  11738. else
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11741. }
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11743. isKnowKey = TRUE;
  11744. }
  11745. #if 1
  11746. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11747. {
  11748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11750. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11751. {
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11753. }
  11754. else
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11757. }
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11759. isKnowKey = TRUE;
  11760. }
  11761. #endif
  11762. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11766. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11767. {
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11769. }
  11770. else
  11771. {
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11773. }
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11775. isKnowKey = TRUE;
  11776. }
  11777. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11781. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11782. {
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11784. }
  11785. else
  11786. {
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11788. }
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11790. isKnowKey = TRUE;
  11791. }
  11792. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11796. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11797. {
  11798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11799. }
  11800. else
  11801. {
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11803. }
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11805. isKnowKey = TRUE;
  11806. }
  11807. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11811. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11812. {
  11813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11814. }
  11815. else
  11816. {
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11818. }
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11820. isKnowKey = TRUE;
  11821. }
  11822. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11826. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11827. {
  11828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11829. }
  11830. else
  11831. {
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11833. }
  11834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11835. isKnowKey = TRUE;
  11836. }
  11837. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11841. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11842. {
  11843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11844. }
  11845. else
  11846. {
  11847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11848. }
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11850. isKnowKey = TRUE;
  11851. }
  11852. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11856. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11857. {
  11858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11859. }
  11860. else
  11861. {
  11862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11863. }
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11865. isKnowKey = TRUE;
  11866. }
  11867. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11871. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11872. {
  11873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11874. }
  11875. else
  11876. {
  11877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11878. }
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11880. isKnowKey = TRUE;
  11881. }
  11882. //=========================================================
  11883. if(!isEmpty && !isKnowKey)
  11884. {
  11885. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11886. strcpy(unknownkey[UnknownKeynum], keyReq);
  11887. UnknownKeynum = UnknownKeynum + 1;
  11888. }
  11889. }
  11890. void processUnkownKey(void)
  11891. {
  11892. DEBUG_INFO("processUnkownKey...\n");
  11893. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11894. for(int index=0; index < UnknownKeynum; index++)
  11895. {
  11896. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11897. {
  11898. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11899. }
  11900. }
  11901. }
  11902. int setKeyValue(char *key, char *value)
  11903. {
  11904. int isSuccess = NotSupported;
  11905. int check_ascii=0;
  11906. char str[10]={0};
  11907. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11908. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11909. {
  11910. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11912. {
  11913. strcpy(str, (const char*)value);
  11914. for(int i = 0; str[i]; i++){
  11915. str[i] = tolower(str[i]);
  11916. }
  11917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11918. isSuccess = ConfigurationStatus_Accepted;
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11926. {
  11927. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11929. {
  11930. strcpy(str, (const char*)value);
  11931. for(int i = 0; str[i]; i++){
  11932. str[i] = tolower(str[i]);
  11933. }
  11934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11935. isSuccess = ConfigurationStatus_Accepted;
  11936. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11937. }
  11938. else
  11939. {
  11940. isSuccess = ConfigurationStatus_Rejected;
  11941. }
  11942. }
  11943. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11944. {
  11945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11946. {
  11947. strcpy(str, (const char*)value);
  11948. for(int i = 0; str[i]; i++)
  11949. {
  11950. str[i] = tolower(str[i]);
  11951. }
  11952. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11954. isSuccess = ConfigurationStatus_Accepted;
  11955. }
  11956. else
  11957. {
  11958. isSuccess = ConfigurationStatus_Rejected;
  11959. }
  11960. }
  11961. if(strcmp(key, "BlinkRepeat") == 0)
  11962. {
  11963. //Charger.BlinkRepeat = Integer.parseInt(value);
  11964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11965. {
  11966. check_ascii = value[0];
  11967. if( (check_ascii < 48) || (check_ascii > 57) )
  11968. {
  11969. isSuccess = ConfigurationStatus_Rejected;
  11970. }
  11971. else
  11972. {
  11973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11974. isSuccess = ConfigurationStatus_Accepted;
  11975. }
  11976. }
  11977. else
  11978. {
  11979. isSuccess = ConfigurationStatus_Rejected;
  11980. }
  11981. }
  11982. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11983. {
  11984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11985. {
  11986. check_ascii = value[0];
  11987. if( (check_ascii < 48) || (check_ascii > 57) )
  11988. {
  11989. isSuccess = ConfigurationStatus_Rejected;
  11990. }
  11991. else
  11992. {
  11993. if((atoi(value) == 0) || (atoi(value) >= 10))
  11994. {
  11995. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11997. isSuccess = ConfigurationStatus_Accepted;
  11998. }
  11999. else
  12000. isSuccess = ConfigurationStatus_Rejected;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12011. {
  12012. check_ascii = value[0];
  12013. if( (check_ascii < 48) || (check_ascii > 57) )
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. else
  12018. {
  12019. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12021. isSuccess = ConfigurationStatus_Accepted;
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12032. {
  12033. check_ascii = value[0];
  12034. if( (check_ascii < 48) || (check_ascii > 57) )
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. else
  12039. {
  12040. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12042. isSuccess = ConfigurationStatus_Accepted;
  12043. }
  12044. }
  12045. else
  12046. {
  12047. isSuccess = ConfigurationStatus_Rejected;
  12048. }
  12049. }
  12050. if(strcmp(key, "HeartbeatInterval") == 0)
  12051. {
  12052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12053. {
  12054. check_ascii = value[0];
  12055. if( (check_ascii < 48) || (check_ascii > 57) )
  12056. {
  12057. isSuccess = ConfigurationStatus_Rejected;
  12058. }
  12059. else
  12060. {
  12061. if((atoi(value) == 0) || (atoi(value) >= 10))
  12062. {
  12063. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12065. HeartBeatWaitTime = atoi(value);
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. else
  12069. {
  12070. isSuccess = ConfigurationStatus_Rejected;
  12071. }
  12072. }
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "LightIntensity") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12082. {
  12083. check_ascii = value[0];
  12084. if( (check_ascii < 48) || (check_ascii > 57) )
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. else
  12089. {
  12090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12091. isSuccess = ConfigurationStatus_Accepted;
  12092. }
  12093. }
  12094. else
  12095. {
  12096. isSuccess = ConfigurationStatus_Rejected;
  12097. }
  12098. }
  12099. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12100. {
  12101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12102. {
  12103. strcpy(str, (const char*)value);
  12104. for(int i = 0; str[i]; i++)
  12105. {
  12106. str[i] = tolower(str[i]);
  12107. }
  12108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12109. isSuccess = ConfigurationStatus_Accepted;
  12110. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "LocalPreAuthorize") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12120. {
  12121. strcpy(str, (const char*)value);
  12122. for(int i = 0; str[i]; i++)
  12123. {
  12124. str[i] = tolower(str[i]);
  12125. }
  12126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12127. isSuccess = ConfigurationStatus_Accepted;
  12128. }
  12129. else
  12130. {
  12131. isSuccess = ConfigurationStatus_Rejected;
  12132. }
  12133. }
  12134. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12135. {
  12136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12137. {
  12138. check_ascii = value[0];
  12139. if( (check_ascii < 48) || (check_ascii > 57) )
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. else
  12144. {
  12145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12146. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. }
  12150. else
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. }
  12155. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12156. {
  12157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12158. {
  12159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12160. isSuccess = ConfigurationStatus_Accepted;
  12161. }
  12162. else
  12163. {
  12164. isSuccess = ConfigurationStatus_Rejected;
  12165. }
  12166. }
  12167. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12168. {
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12170. {
  12171. check_ascii = value[0];
  12172. if( (check_ascii < 48) || (check_ascii > 57) )
  12173. {
  12174. isSuccess = ConfigurationStatus_Rejected;
  12175. }
  12176. else
  12177. {
  12178. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12180. isSuccess = ConfigurationStatus_Accepted;
  12181. }
  12182. }
  12183. else
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. }
  12188. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12189. {
  12190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12191. {
  12192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12193. isSuccess = ConfigurationStatus_Accepted;
  12194. }
  12195. else
  12196. {
  12197. isSuccess = ConfigurationStatus_Rejected;
  12198. }
  12199. }
  12200. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12201. {
  12202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12203. {
  12204. check_ascii = value[0];
  12205. if( (check_ascii < 48) || (check_ascii > 57) )
  12206. {
  12207. isSuccess = ConfigurationStatus_Rejected;
  12208. }
  12209. else
  12210. {
  12211. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12213. isSuccess = ConfigurationStatus_Accepted;
  12214. }
  12215. }
  12216. else
  12217. {
  12218. isSuccess = ConfigurationStatus_Rejected;
  12219. }
  12220. }
  12221. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12222. {
  12223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12224. {
  12225. check_ascii = value[0];
  12226. if( (check_ascii < 48) || (check_ascii > 57) )
  12227. {
  12228. isSuccess = ConfigurationStatus_Rejected;
  12229. }
  12230. else
  12231. {
  12232. if((atoi(value) == 0) || (atoi(value) >= 10))
  12233. {
  12234. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12236. isSuccess = ConfigurationStatus_Accepted;
  12237. }
  12238. else
  12239. {
  12240. isSuccess = ConfigurationStatus_Rejected;
  12241. }
  12242. }
  12243. }
  12244. else
  12245. {
  12246. isSuccess = ConfigurationStatus_Rejected;
  12247. }
  12248. }
  12249. if(strcmp(key, "MinimumStatusDuration") == 0)
  12250. {
  12251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12252. {
  12253. check_ascii = value[0];
  12254. if( (check_ascii < 48) || (check_ascii > 57) )
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. else
  12259. {
  12260. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. else
  12265. {
  12266. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12268. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12269. isSuccess = ConfigurationStatus_Accepted;
  12270. }
  12271. }
  12272. }
  12273. else
  12274. {
  12275. isSuccess = ConfigurationStatus_Rejected;
  12276. }
  12277. }
  12278. if(strcmp(key, "NumberOfConnectors") == 0)
  12279. {
  12280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12281. {
  12282. check_ascii = value[0];
  12283. if( (check_ascii < 48) || (check_ascii > 57) )
  12284. {
  12285. isSuccess = ConfigurationStatus_Rejected;
  12286. }
  12287. else
  12288. {
  12289. //Charger.ResetRetries = Integer.parseInt(value);
  12290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12291. isSuccess = ConfigurationStatus_Accepted;
  12292. }
  12293. }
  12294. else
  12295. {
  12296. isSuccess = ConfigurationStatus_Rejected;
  12297. }
  12298. }
  12299. if(strcmp(key, "ResetRetries") == 0)
  12300. {
  12301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12302. {
  12303. check_ascii = value[0];
  12304. if( (check_ascii < 48) || (check_ascii > 57) )
  12305. {
  12306. isSuccess = ConfigurationStatus_Rejected;
  12307. }
  12308. else
  12309. {
  12310. //Charger.ResetRetries = Integer.parseInt(value);
  12311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12312. isSuccess = ConfigurationStatus_Accepted;
  12313. }
  12314. }
  12315. else
  12316. {
  12317. isSuccess = ConfigurationStatus_Rejected;
  12318. }
  12319. }
  12320. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12321. {
  12322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12323. {
  12324. strcpy(str, (const char*)value);
  12325. for(int i = 0; str[i]; i++)
  12326. {
  12327. str[i] = tolower(str[i]);
  12328. }
  12329. if(strcmp(str, "notapplicable")== 0)
  12330. {
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12332. isSuccess = ConfigurationStatus_Accepted;
  12333. }
  12334. else if(strcmp(str, "unknown")== 0)
  12335. {
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. else if(strcmp(str, "rst")== 0)
  12340. {
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12342. isSuccess = ConfigurationStatus_Accepted;
  12343. }
  12344. else if(strcmp(str, "rts")== 0)
  12345. {
  12346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12347. isSuccess = ConfigurationStatus_Accepted;
  12348. }
  12349. else if(strcmp(str, "srt")== 0)
  12350. {
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12352. isSuccess = ConfigurationStatus_Accepted;
  12353. }
  12354. else if(strcmp(str, "str")== 0)
  12355. {
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12357. isSuccess = ConfigurationStatus_Accepted;
  12358. }
  12359. else if(strcmp(str, "trs")== 0)
  12360. {
  12361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12362. isSuccess = ConfigurationStatus_Accepted;
  12363. }
  12364. else if(strcmp(str, "tsr")== 0)
  12365. {
  12366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12367. isSuccess = ConfigurationStatus_Accepted;
  12368. }
  12369. else
  12370. {
  12371. isSuccess = ConfigurationStatus_Rejected;
  12372. }
  12373. }
  12374. else
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. }
  12379. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12380. {
  12381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12382. {
  12383. check_ascii = value[0];
  12384. if( (check_ascii < 48) || (check_ascii > 57) )
  12385. {
  12386. isSuccess = ConfigurationStatus_Rejected;
  12387. }
  12388. else
  12389. {
  12390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12391. isSuccess = ConfigurationStatus_Accepted;
  12392. }
  12393. }
  12394. else
  12395. {
  12396. isSuccess = ConfigurationStatus_Rejected;
  12397. }
  12398. }
  12399. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12400. {
  12401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12402. {
  12403. strcpy(str, (const char*)value);
  12404. for(int i = 0; str[i]; i++)
  12405. {
  12406. str[i] = tolower(str[i]);
  12407. }
  12408. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12410. isSuccess = ConfigurationStatus_Accepted;
  12411. }
  12412. else
  12413. {
  12414. isSuccess = ConfigurationStatus_Rejected;
  12415. }
  12416. }
  12417. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12418. {
  12419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12420. {
  12421. strcpy(str, (const char*)value);
  12422. for(int i = 0; str[i]; i++)
  12423. {
  12424. str[i] = tolower(str[i]);
  12425. }
  12426. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12428. isSuccess = ConfigurationStatus_Accepted;
  12429. }
  12430. else
  12431. {
  12432. isSuccess = ConfigurationStatus_Rejected;
  12433. }
  12434. }
  12435. if(strcmp(key, "StopTxnAlignedData") == 0)
  12436. {
  12437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12438. {
  12439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12440. isSuccess = ConfigurationStatus_Accepted;
  12441. }
  12442. else
  12443. {
  12444. isSuccess = ConfigurationStatus_Rejected;
  12445. }
  12446. }
  12447. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12448. {
  12449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12450. {
  12451. check_ascii = value[0];
  12452. if( (check_ascii < 48) || (check_ascii > 57) )
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. else
  12457. {
  12458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12459. isSuccess = ConfigurationStatus_Accepted;
  12460. }
  12461. }
  12462. else
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. }
  12467. if(strcmp(key, "StopTxnSampledData") == 0)
  12468. {
  12469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12470. {
  12471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12472. isSuccess = ConfigurationStatus_Accepted;
  12473. }
  12474. else
  12475. {
  12476. isSuccess = ConfigurationStatus_Rejected;
  12477. }
  12478. }
  12479. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12480. {
  12481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12482. {
  12483. check_ascii = value[0];
  12484. if( (check_ascii < 48) || (check_ascii > 57) )
  12485. {
  12486. isSuccess = ConfigurationStatus_Rejected;
  12487. }
  12488. else
  12489. {
  12490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12491. isSuccess = ConfigurationStatus_Accepted;
  12492. }
  12493. }
  12494. else
  12495. {
  12496. isSuccess = ConfigurationStatus_Rejected;
  12497. }
  12498. }
  12499. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12500. {
  12501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12502. {
  12503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12504. isSuccess = ConfigurationStatus_Accepted;
  12505. }
  12506. else
  12507. {
  12508. isSuccess = ConfigurationStatus_Rejected;
  12509. }
  12510. }
  12511. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12512. {
  12513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12514. {
  12515. check_ascii = value[0];
  12516. if( (check_ascii < 48) || (check_ascii > 57) )
  12517. {
  12518. isSuccess = ConfigurationStatus_Rejected;
  12519. }
  12520. else
  12521. {
  12522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12523. isSuccess = ConfigurationStatus_Accepted;
  12524. }
  12525. }
  12526. else
  12527. {
  12528. isSuccess = ConfigurationStatus_Rejected;
  12529. }
  12530. }
  12531. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12532. {
  12533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12534. {
  12535. check_ascii = value[0];
  12536. if( (check_ascii < 48) || (check_ascii > 57) )
  12537. {
  12538. isSuccess = ConfigurationStatus_Rejected;
  12539. }
  12540. else
  12541. {
  12542. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12544. TransactionMessageAttemptsValue = atoi(value);
  12545. isSuccess = ConfigurationStatus_Accepted;
  12546. }
  12547. }
  12548. else
  12549. {
  12550. isSuccess = ConfigurationStatus_Rejected;
  12551. }
  12552. }
  12553. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12554. {
  12555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12556. {
  12557. check_ascii = value[0];
  12558. if( (check_ascii < 48) || (check_ascii > 57) )
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. else
  12563. {
  12564. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12566. TransactionMessageRetryIntervalValue = atoi(value);
  12567. isSuccess = ConfigurationStatus_Accepted;
  12568. }
  12569. }
  12570. else
  12571. {
  12572. isSuccess = ConfigurationStatus_Rejected;
  12573. }
  12574. }
  12575. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12576. {
  12577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12578. {
  12579. strcpy(str, (const char*)value);
  12580. for(int i = 0; str[i]; i++)
  12581. {
  12582. str[i] = tolower(str[i]);
  12583. }
  12584. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12586. isSuccess = ConfigurationStatus_Accepted;
  12587. }
  12588. else
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. }
  12593. if(strcmp(key, "WebSocketPingInterval") == 0)
  12594. {
  12595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12596. {
  12597. check_ascii = value[0];
  12598. if( (check_ascii < 48) || (check_ascii > 57) )
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. else
  12603. {
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12605. isSuccess = ConfigurationStatus_Accepted;
  12606. }
  12607. }
  12608. else
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. }
  12613. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12614. {
  12615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12616. {
  12617. strcpy(str, (const char*)value);
  12618. for(int i = 0; str[i]; i++)
  12619. {
  12620. str[i] = tolower(str[i]);
  12621. }
  12622. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12624. isSuccess = ConfigurationStatus_Accepted;
  12625. }
  12626. else
  12627. {
  12628. isSuccess = ConfigurationStatus_Rejected;
  12629. }
  12630. }
  12631. if(strcmp(key, "AuthorizationKey") == 0)
  12632. {
  12633. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12634. {
  12635. strcpy(str, (const char*)value);
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12637. isSuccess = ConfigurationStatus_Accepted;
  12638. }
  12639. else
  12640. {
  12641. isSuccess = ConfigurationStatus_Rejected;
  12642. }
  12643. }
  12644. if(strcmp(key, "SecurityProfile") == 0)
  12645. {
  12646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12647. {
  12648. check_ascii = value[0];
  12649. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. else if(check_ascii == 0x33)
  12654. {
  12655. isSuccess = NotSupported;
  12656. }
  12657. else
  12658. {
  12659. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12660. {
  12661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12662. isSuccess = ConfigurationStatus_Accepted;
  12663. }
  12664. else
  12665. isSuccess = ConfigurationStatus_Rejected;
  12666. }
  12667. }
  12668. else
  12669. {
  12670. isSuccess = ConfigurationStatus_Rejected;
  12671. }
  12672. }
  12673. if(strcmp(key, "DefaultPrice") == 0)
  12674. {
  12675. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12676. {
  12677. strcpy(str, (const char*)value);
  12678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12679. isSuccess = ConfigurationStatus_Accepted;
  12680. }
  12681. else
  12682. {
  12683. isSuccess = ConfigurationStatus_Rejected;
  12684. }
  12685. }
  12686. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12687. {
  12688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12689. {
  12690. strcpy(str, (const char*)value);
  12691. for(int i = 0; str[i]; i++)
  12692. {
  12693. str[i] = tolower(str[i]);
  12694. }
  12695. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12697. isSuccess = ConfigurationStatus_Accepted;
  12698. }
  12699. else
  12700. {
  12701. isSuccess = ConfigurationStatus_Rejected;
  12702. }
  12703. }
  12704. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12705. {
  12706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12707. {
  12708. strcpy(str, (const char*)value);
  12709. for(int i = 0; str[i]; i++)
  12710. {
  12711. str[i] = tolower(str[i]);
  12712. }
  12713. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12715. isSuccess = ConfigurationStatus_Accepted;
  12716. }
  12717. else
  12718. {
  12719. isSuccess = ConfigurationStatus_Rejected;
  12720. }
  12721. }
  12722. #if 0
  12723. //For OCPP Test Case
  12724. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12725. {
  12726. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12727. {
  12728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12729. isSuccess = ConfigurationStatus_Accepted;
  12730. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12731. }
  12732. else
  12733. {
  12734. isSuccess = ConfigurationStatus_Rejected;
  12735. }
  12736. }
  12737. #endif
  12738. #if 1
  12739. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12742. {
  12743. strcpy(str, (const char*)value);
  12744. for(int i = 0; str[i]; i++)
  12745. {
  12746. str[i] = tolower(str[i]);
  12747. }
  12748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12749. isSuccess = ConfigurationStatus_Accepted;
  12750. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12751. }
  12752. else
  12753. {
  12754. isSuccess = ConfigurationStatus_Rejected;
  12755. }
  12756. }
  12757. #endif
  12758. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12759. {
  12760. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12761. {
  12762. check_ascii = value[0];
  12763. if( (check_ascii < 48) || (check_ascii > 57) )
  12764. {
  12765. isSuccess = ConfigurationStatus_Rejected;
  12766. }
  12767. else
  12768. {
  12769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12770. isSuccess = ConfigurationStatus_Accepted;
  12771. }
  12772. }
  12773. else
  12774. {
  12775. isSuccess = ConfigurationStatus_Rejected;
  12776. }
  12777. }
  12778. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12779. {
  12780. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12781. {
  12782. check_ascii = value[0];
  12783. if( (check_ascii < 48) || (check_ascii > 57) )
  12784. {
  12785. isSuccess = ConfigurationStatus_Rejected;
  12786. }
  12787. else
  12788. {
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12790. isSuccess = ConfigurationStatus_Accepted;
  12791. }
  12792. }
  12793. else
  12794. {
  12795. isSuccess = ConfigurationStatus_Rejected;
  12796. }
  12797. }
  12798. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12799. {
  12800. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12801. {
  12802. strcpy(str, (const char*)value);
  12803. for(int i = 0; str[i]; i++)
  12804. {
  12805. str[i] = tolower(str[i]);
  12806. }
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12808. isSuccess = ConfigurationStatus_Accepted;
  12809. }
  12810. else
  12811. {
  12812. isSuccess = ConfigurationStatus_Rejected;
  12813. }
  12814. }
  12815. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12816. {
  12817. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12818. {
  12819. check_ascii = value[0];
  12820. if( (check_ascii < 48) || (check_ascii > 57) )
  12821. {
  12822. isSuccess = ConfigurationStatus_Rejected;
  12823. }
  12824. else
  12825. {
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12827. isSuccess = ConfigurationStatus_Accepted;
  12828. }
  12829. }
  12830. else
  12831. {
  12832. isSuccess = ConfigurationStatus_Rejected;
  12833. }
  12834. }
  12835. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12836. {
  12837. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12838. {
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12840. isSuccess = ConfigurationStatus_Accepted;
  12841. }
  12842. else
  12843. {
  12844. isSuccess = ConfigurationStatus_Rejected;
  12845. }
  12846. }
  12847. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12848. {
  12849. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12850. {
  12851. check_ascii = value[0];
  12852. if( (check_ascii < 48) || (check_ascii > 57) )
  12853. {
  12854. isSuccess = ConfigurationStatus_Rejected;
  12855. }
  12856. else
  12857. {
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12859. isSuccess = ConfigurationStatus_Accepted;
  12860. }
  12861. }
  12862. else
  12863. {
  12864. isSuccess = ConfigurationStatus_Rejected;
  12865. }
  12866. }
  12867. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12868. {
  12869. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12870. {
  12871. strcpy(str, (const char*)value);
  12872. for(int i = 0; str[i]; i++)
  12873. {
  12874. str[i] = tolower(str[i]);
  12875. }
  12876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12877. isSuccess = ConfigurationStatus_Accepted;
  12878. }
  12879. else
  12880. {
  12881. isSuccess = ConfigurationStatus_Rejected;
  12882. }
  12883. }
  12884. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12885. {
  12886. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12887. {
  12888. check_ascii = value[0];
  12889. if( (check_ascii < 48) || (check_ascii > 57) )
  12890. {
  12891. isSuccess = ConfigurationStatus_Rejected;
  12892. }
  12893. else
  12894. {
  12895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12896. isSuccess = ConfigurationStatus_Accepted;
  12897. }
  12898. }
  12899. else
  12900. {
  12901. isSuccess = ConfigurationStatus_Rejected;
  12902. }
  12903. }
  12904. return isSuccess;
  12905. }
  12906. int TransactionMessageAttemptsGet(void)
  12907. {
  12908. return TransactionMessageAttemptsValue;
  12909. }
  12910. int FirstHeartBeatResponse(void)
  12911. {
  12912. return FirstHeartBeat;
  12913. }
  12914. int TransactionMessageRetryIntervalGet(void)
  12915. {
  12916. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12917. }
  12918. int ReadHttpStatus(int sock)
  12919. {
  12920. //char c;
  12921. char buff[1024]="",*ptr=buff+1;
  12922. int bytes_received, status;
  12923. DEBUG_INFO("Begin Response ..\n");
  12924. while((bytes_received = recv(sock, ptr, 1, 0))){
  12925. if(bytes_received==-1){
  12926. perror("ReadHttpStatus");
  12927. exit(1);
  12928. }
  12929. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12930. ptr++;
  12931. }
  12932. *ptr=0;
  12933. ptr=buff+1;
  12934. sscanf(ptr,"%*s %d ", &status);
  12935. DEBUG_INFO("%s\n",ptr);
  12936. DEBUG_INFO("status=%d\n",status);
  12937. DEBUG_INFO("End Response ..\n");
  12938. return (bytes_received>0)?status:0;
  12939. }
  12940. //the only filed that it parsed is 'Content-Length'
  12941. int ParseHeader(int sock)
  12942. {
  12943. //char c;
  12944. char buff[1024]="",*ptr=buff+4;
  12945. int bytes_received;
  12946. DEBUG_INFO("Begin HEADER ..\n");
  12947. while((bytes_received = recv(sock, ptr, 1, 0))){
  12948. if(bytes_received==-1){
  12949. perror("Parse Header");
  12950. exit(1);
  12951. }
  12952. if(
  12953. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12954. (ptr[-1]=='\r') && (*ptr=='\n' )
  12955. ) break;
  12956. ptr++;
  12957. }
  12958. *ptr=0;
  12959. ptr=buff+4;
  12960. //printf("%s",ptr);
  12961. if(bytes_received){
  12962. ptr=strstr(ptr,"Content-Length:");
  12963. if(ptr){
  12964. sscanf(ptr,"%*s %d",&bytes_received);
  12965. }else
  12966. bytes_received=-1; //unknown size
  12967. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12968. }
  12969. DEBUG_INFO("End HEADER ..\n");
  12970. return bytes_received ;
  12971. }
  12972. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12973. {
  12974. char rmFileCmd[100]={0};
  12975. char FilePath[100]={0};
  12976. char ftpbuf[200];
  12977. int systemresult;
  12978. //DEBUG_INFO("filename=%s\n",filename);
  12979. //DEBUG_INFO("url=%s\n",url);
  12980. sprintf(FilePath,"/mnt/%s",filename);
  12981. if((access(FilePath,F_OK))!=-1)
  12982. {
  12983. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12984. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12985. system(rmFileCmd);
  12986. }
  12987. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12988. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12989. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12990. systemresult = system(ftpbuf);
  12991. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12992. if(systemresult != 0)
  12993. {
  12994. DEBUG_INFO("http DownLoad error!\n");
  12995. return FALSE;
  12996. }
  12997. return TRUE;
  12998. }
  12999. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13000. {
  13001. char rmFileCmd[100]={0};
  13002. char FilePath[100]={0};
  13003. char ftpbuf[200];
  13004. int systemresult;
  13005. //char temp[100];
  13006. sprintf(FilePath,"/mnt/%s",filename);
  13007. if((access(FilePath,F_OK))!=-1)
  13008. {
  13009. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13010. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13011. system(rmFileCmd);
  13012. }
  13013. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13014. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13015. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13016. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13017. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13018. systemresult = system(ftpbuf);
  13019. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13020. if(systemresult != 0)
  13021. {
  13022. printf("wget error!\n");
  13023. return FALSE;
  13024. }
  13025. return TRUE;
  13026. }
  13027. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13028. {
  13029. char rmFileCmd[100]={0};
  13030. char FilePath[100]={0};
  13031. char ftpbuf[200];
  13032. int systemresult;
  13033. //DEBUG_INFO("filename=%s\n",filename);
  13034. //DEBUG_INFO("url=%s\n",url);
  13035. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13036. if((access(FilePath,F_OK))!=-1)
  13037. {
  13038. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13039. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13040. system(rmFileCmd);
  13041. }
  13042. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13043. if(fp == NULL)
  13044. {
  13045. DEBUG_INFO("log is NULL\n");
  13046. return FALSE;
  13047. }
  13048. else
  13049. {
  13050. fprintf(fp, "%s\n", url);
  13051. fprintf(fp, "%s\n", filename);
  13052. fclose(fp);
  13053. }
  13054. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13055. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13056. systemresult = system(ftpbuf);
  13057. DEBUG_INFO("systemresult = %d\n",systemresult);
  13058. if(systemresult != 0)
  13059. {
  13060. DEBUG_INFO("http upload error!\n");
  13061. return FALSE;
  13062. }
  13063. return TRUE;
  13064. }
  13065. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13066. {
  13067. struct hostent* server;
  13068. char *IPbuffer;
  13069. char ftpbuf[200];
  13070. int systemresult;
  13071. // To retrieve host information
  13072. server = gethostbyname(location);
  13073. // To convert an Internet network
  13074. // address into ASCII string
  13075. IPbuffer = inet_ntoa(*((struct in_addr*)
  13076. server->h_addr_list[0]));
  13077. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13078. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13079. /* format : ftpput -u username -p passwd IP target source*/
  13080. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13081. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13082. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13083. systemresult = system(ftpbuf);
  13084. DEBUG_INFO("systemresult=%d\n",systemresult);
  13085. if(systemresult != 0)
  13086. {
  13087. DEBUG_INFO("ftpput error!\n");
  13088. return FALSE;
  13089. }
  13090. return TRUE;
  13091. }
  13092. /**
  13093. * Place the contents of the specified file into a memory buffer
  13094. *
  13095. * @param[in] filename The path and name of the file to read
  13096. * @param[out] filebuffer A pointer to the contents in memory
  13097. * @return status 0 success, 1 on failure
  13098. */
  13099. int get_file_contents(const char* filename, char** outbuffer) {
  13100. FILE* file = NULL;
  13101. long filesize;
  13102. const int blocksize = 1;
  13103. size_t readsize;
  13104. char* filebuffer;
  13105. // Open the file
  13106. file = fopen(filename, "r");
  13107. if (NULL == file)
  13108. {
  13109. printf("'%s' not opened\n", filename);
  13110. exit(EXIT_FAILURE);
  13111. }
  13112. // Determine the file size
  13113. fseek(file, 0, SEEK_END);
  13114. filesize = ftell(file);
  13115. rewind (file);
  13116. // Allocate memory for the file contents
  13117. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13118. *outbuffer = filebuffer;
  13119. if (filebuffer == NULL)
  13120. {
  13121. fputs ("malloc out-of-memory", stderr);
  13122. exit(EXIT_FAILURE);
  13123. }
  13124. // Read in the file
  13125. readsize = fread(filebuffer, blocksize, filesize, file);
  13126. if (readsize != filesize)
  13127. {
  13128. fputs ("didn't read file completely",stderr);
  13129. exit(EXIT_FAILURE);
  13130. }
  13131. // Clean exit
  13132. fclose(file);
  13133. return EXIT_SUCCESS;
  13134. }
  13135. static int selectSqlCount = 0;
  13136. static int callback(void *data, int argc, char **argv, char **azColName){
  13137. int i;
  13138. //printf("%s: ", (const char*)data);
  13139. selectSqlCount = argc;
  13140. for(i = 0; i<argc; i++){
  13141. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13142. }
  13143. //printf("\n");
  13144. return 0;
  13145. }
  13146. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13147. //int i;
  13148. //printf("%s:\n", (const char*)data);
  13149. localversion = argv[5] ? atoi(argv[5]) : 0;
  13150. //printf("localversion=%d\n", localversion);
  13151. return 0;
  13152. }
  13153. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13154. //int i;
  13155. //printf("%s:\n", (const char*)data);
  13156. //idTag
  13157. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13158. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13159. //parentIdTag
  13160. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13161. //expir_date
  13162. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13163. //status
  13164. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13165. //version
  13166. idTagQuery.listVersionInt = atoi(argv[5]);
  13167. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13168. return 0;
  13169. }
  13170. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13171. {
  13172. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13173. // printf("localversion=%d\n", localversion);
  13174. return 0;
  13175. }
  13176. //=========================================
  13177. // Sqlite3 related function
  13178. //=========================================
  13179. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13180. {
  13181. for (int i = 0; i < n_columns; i++)
  13182. {
  13183. DEBUG_INFO("%s\t", col_values[i]);
  13184. }
  13185. DEBUG_INFO("\n");
  13186. return 0;
  13187. }
  13188. void OCPP_getListVerion()
  13189. {
  13190. int rc = 0;
  13191. // const char* data = "Callback function called";
  13192. char sql[100];
  13193. char zErrMsg[100];
  13194. memset(sql, 0, 100);
  13195. memset(zErrMsg, 0, 100);
  13196. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13197. /* Execute SQL statement */
  13198. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13199. if( rc != SQLITE_OK )
  13200. {
  13201. DEBUG_INFO("SQL error: %s", zErrMsg);
  13202. }
  13203. }
  13204. void OCPP_getIdTag(char idTag[])
  13205. {
  13206. int rc = 0;
  13207. // const char* data = "Callback function called";
  13208. char sql[100];
  13209. char zErrMsg[100];
  13210. memset(sql, 0, 100);
  13211. memset(zErrMsg, 0, 100);
  13212. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13213. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13214. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13215. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13216. /* Execute SQL statement */
  13217. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13218. if( rc != SQLITE_OK )
  13219. {
  13220. DEBUG_INFO("SQL error: %s", zErrMsg);
  13221. }
  13222. //return ver;
  13223. }
  13224. void OCPP_get_TableAuthlocalAllData(void)
  13225. {
  13226. int rc = 0;
  13227. char sql[100];
  13228. char zErrMsg[100];
  13229. memset(sql, 0, 100);
  13230. memset(zErrMsg, 0, 100);
  13231. sprintf(sql,"select * from ocpp_auth_local ");
  13232. /* Execute SQL statement */
  13233. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13234. if( rc != SQLITE_OK )
  13235. {
  13236. DEBUG_INFO("SQL error: %s", zErrMsg);
  13237. }
  13238. //return ver;
  13239. }
  13240. int OCPP_cleanLocalList()
  13241. {
  13242. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13243. char *errMsg = 0;
  13244. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13245. if (SQLITE_OK != rc)
  13246. {
  13247. DEBUG_INFO("%s\n",errMsg);
  13248. return FALSE;
  13249. }
  13250. return TRUE;
  13251. }
  13252. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13253. {
  13254. int isSuccess = FALSE;
  13255. int ret = 0;
  13256. //const char* data = "Callback function called";
  13257. char sql[300];
  13258. char zErrMsg[200];
  13259. memset(sql, 0, 300);
  13260. memset(zErrMsg, 0, 200);
  13261. 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);
  13262. //* Execute SQL statement */
  13263. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13264. if( ret != SQLITE_OK )
  13265. {
  13266. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13267. return isSuccess;
  13268. }
  13269. memset(sql, 0, 300);
  13270. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13271. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13272. if( ret != SQLITE_OK )
  13273. {
  13274. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13275. return isSuccess;
  13276. }
  13277. isSuccess = TRUE;
  13278. return isSuccess;
  13279. }
  13280. void OCPP_deleteIdTag(char idTag[])
  13281. {
  13282. //int ver = 0;
  13283. //int isSuccess = FALSE;
  13284. int rc = 0;
  13285. char sql[100];
  13286. char zErrMsg[100];
  13287. memset(sql, 0, 100);
  13288. memset(zErrMsg, 0, 100);
  13289. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13290. //* Execute SQL statement */
  13291. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13292. if( rc != SQLITE_OK )
  13293. {
  13294. DEBUG_INFO("SQL error: %s", zErrMsg);
  13295. }
  13296. }
  13297. int GetOcppServerURL()
  13298. {
  13299. int result = FALSE;
  13300. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13301. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13302. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13303. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13304. {
  13305. #if 1
  13306. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13307. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13308. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13309. #endif
  13310. result = TRUE;
  13311. goto End;
  13312. }
  13313. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13314. {
  13315. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13316. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13317. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13318. result = TRUE;
  13319. goto End;
  13320. }
  13321. else
  13322. {
  13323. strcpy(OcppHost,"");
  13324. }
  13325. End:
  13326. return result;
  13327. }
  13328. int GetOcppPath()
  13329. {
  13330. int result = FALSE;
  13331. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13332. {
  13333. if(OcppTempPath == NULL)
  13334. {
  13335. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13336. }
  13337. else
  13338. {
  13339. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13340. }
  13341. result = TRUE;
  13342. goto End;
  13343. }
  13344. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13345. {
  13346. if(OcppTempPath == NULL)
  13347. {
  13348. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13349. }
  13350. else
  13351. {
  13352. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13353. }
  13354. result = TRUE;
  13355. goto End;
  13356. }
  13357. else
  13358. {
  13359. strcpy(OcppPath,"");
  13360. }
  13361. End:
  13362. return result;
  13363. }
  13364. int GetOcppPort()
  13365. {
  13366. return OcppPort;
  13367. }
  13368. int GetOcppConnStatus(void)
  13369. {
  13370. return ShmOCPP16Data->OcppConnStatus;
  13371. }
  13372. void SetOcppConnStatus(uint8_t status)
  13373. {
  13374. ShmOCPP16Data->OcppConnStatus = status;
  13375. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13376. }
  13377. int GetHeartBeatWithNOResponse(void)
  13378. {
  13379. return HeartBeatWithNOResponse;
  13380. }
  13381. void SetHeartBeatWithNOResponse(void)
  13382. {
  13383. HeartBeatWithNOResponse = 0;
  13384. }
  13385. void GetStartTransactionIdTag(int gun_index)
  13386. {
  13387. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13388. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13389. }
  13390. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13391. {
  13392. char ch;
  13393. FILE *fptr1;
  13394. int temptransactionId;
  13395. char str[100]={0};
  13396. temptransactionId = 0;
  13397. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13398. {
  13399. DEBUG_INFO("IdTag is empty.\n");
  13400. return temptransactionId;
  13401. }
  13402. /*------ Read the file ----------------*/
  13403. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13404. if (!fptr1)
  13405. {
  13406. DEBUG_INFO("QueueTransactionId file open error.\n");
  13407. //printf(" File not found or unable to open the input file!!\n");
  13408. return temptransactionId;
  13409. }
  13410. ch=fgetc(fptr1);
  13411. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13412. rewind(fptr1);
  13413. if(ch!=EOF)
  13414. {
  13415. // printf("%c",ch);
  13416. while (fgets(str, 100, fptr1) != NULL)
  13417. {
  13418. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13419. if(str[0]=='\0')
  13420. {
  13421. break;
  13422. }
  13423. char *revbuf[8] = {0}; //存放分割後的子字串
  13424. int num = 0;//分割後子字串的個數
  13425. DEBUG_INFO("str: %s\n", str);
  13426. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13427. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13428. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13429. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13430. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13431. {
  13432. if(isStopTransaction)
  13433. {
  13434. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13435. {
  13436. temptransactionId = atoi(revbuf[2]);
  13437. break;
  13438. }
  13439. }
  13440. else
  13441. {
  13442. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13443. {
  13444. temptransactionId = atoi(revbuf[2]);
  13445. break;
  13446. }
  13447. }
  13448. }
  13449. }
  13450. }
  13451. else
  13452. DEBUG_INFO("EOF\n");
  13453. fclose(fptr1);
  13454. /*------- End of reading ---------------*/
  13455. return temptransactionId;
  13456. }
  13457. void SetTransactionIdZero(int transactionId)
  13458. {
  13459. char ch;
  13460. FILE *fptr1, *fptr2;
  13461. int temptransactionId = 0;
  13462. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13463. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13464. if (!fptr1)
  13465. {
  13466. //printf(" File not found or unable to open the input file!!\n");
  13467. return ;
  13468. }
  13469. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13470. if (!fptr2)
  13471. {
  13472. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13473. fclose(fptr1);
  13474. return ;
  13475. }
  13476. ch=fgetc(fptr1);
  13477. rewind(fptr1);
  13478. if(ch!=EOF)
  13479. {
  13480. // copy all contents to the temporary file except the specific line
  13481. while (fgets(str, 100, fptr1) != NULL)
  13482. {
  13483. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13484. if(str[0]=='\0')
  13485. {
  13486. break;
  13487. }
  13488. char *revbuf[8] = {0};
  13489. int num = 0;
  13490. strcpy(strtemp, str);
  13491. splitstring(str,",",revbuf,&num);
  13492. if(revbuf[2][0] != '\0')
  13493. {
  13494. temptransactionId = atoi(revbuf[2]);
  13495. if(transactionId != temptransactionId)
  13496. {
  13497. fprintf(fptr2, "%s\n", strtemp);
  13498. }
  13499. }
  13500. }
  13501. }
  13502. fclose(fptr1);
  13503. fclose(fptr2);
  13504. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13505. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13506. /*------ Read the file ----------------*/
  13507. }
  13508. int InternetDisconnect(void)
  13509. {
  13510. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13511. }
  13512. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13513. void storeTempStopTransaction(int gun_index)
  13514. {
  13515. char guid[37]={0};
  13516. int tempIndex = 0;
  13517. char TempStopTransaction[256];
  13518. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13519. DEBUG_INFO("storeTempStopTransaction...\n");
  13520. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13521. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13523. if(gunType[gun_index] == 'J')
  13524. {
  13525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13526. {
  13527. tempIndex = ((gun_index==2) ? 1: 0);
  13528. }
  13529. else
  13530. {
  13531. tempIndex = gun_index;
  13532. }
  13533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13534. {
  13535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13536. {
  13537. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13538. }
  13539. }// END OF CHAdeMO_QUANTITY
  13540. }
  13541. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  13552. {
  13553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13554. {
  13555. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13556. }
  13557. }// END OF CCS_QUANTITY
  13558. }
  13559. else if(gunType[gun_index] == 'G')
  13560. {
  13561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13562. {
  13563. tempIndex = ((gun_index==2) ? 1: 0);
  13564. }
  13565. else
  13566. {
  13567. tempIndex = gun_index;
  13568. }
  13569. for (int index = 0; index < GB_QUANTITY; index++)
  13570. {
  13571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13572. {
  13573. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13574. }
  13575. }// END OF GB_QUANTITY
  13576. }
  13577. else if(gunType[gun_index] == 'O')
  13578. {
  13579. tempIndex = gun_index;
  13580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13581. {
  13582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13583. {
  13584. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13585. }
  13586. }
  13587. }
  13588. else
  13589. {
  13590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13591. {
  13592. tempIndex = 2;
  13593. }
  13594. else
  13595. {
  13596. tempIndex = gun_index;
  13597. }
  13598. for (int index = 0; index < AC_QUANTITY; index++)
  13599. {
  13600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13601. {
  13602. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13603. }
  13604. }// END OF AC_QUANTITY
  13605. }
  13606. //Stop Transaction Time
  13607. struct timeval tmnow;
  13608. struct tm *tm;
  13609. char buf[28];//, usec_buf[6];
  13610. gettimeofday(&tmnow, NULL);
  13611. time_t t;
  13612. t = time(NULL);
  13613. /*UTC time and date*/
  13614. tm = gmtime(&t);
  13615. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13617. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13619. random_uuid(guid);
  13620. /***********************************transactionData******************************************************/
  13621. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13623. //=================================
  13624. //1. Transaction_Begin
  13625. //=================================
  13626. //============================== Energy.Active.Import.Interval ===========================================
  13627. //idx_sample=0;
  13628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13631. 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*/]);
  13632. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13633. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13634. {
  13635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13636. }
  13637. else
  13638. {
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13640. }
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13643. //=================================
  13644. //2. Transaction_End
  13645. //=================================
  13646. //2.1====================================== Current.Import L1 ==============================================
  13647. //idx_sample=1;
  13648. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13649. if(gunType[gun_index] == 'J')
  13650. {
  13651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13652. {
  13653. tempIndex = ((gun_index==2) ? 1: 0);
  13654. }
  13655. else
  13656. {
  13657. tempIndex = gun_index;
  13658. }
  13659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13660. {
  13661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13662. {
  13663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13664. }
  13665. }// End of for CHAdeMO_QUANTITY
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13667. }
  13668. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13669. {
  13670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13671. {
  13672. tempIndex = ((gun_index==2) ? 1: 0);
  13673. }
  13674. else
  13675. {
  13676. tempIndex = gun_index;
  13677. }
  13678. for (int index = 0; index < CCS_QUANTITY; index++)
  13679. {
  13680. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13681. {
  13682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13683. }
  13684. }// End of for CCS_QUANTITY
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13686. }
  13687. else if(gunType[gun_index] == 'G')
  13688. {
  13689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13690. {
  13691. tempIndex = ((gun_index==2) ? 1: 0);
  13692. }
  13693. else
  13694. {
  13695. tempIndex = gun_index;
  13696. }
  13697. for (int index = 0; index < GB_QUANTITY; index++)
  13698. {
  13699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13700. {
  13701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13702. }
  13703. }// End of for GB_QUANTITY
  13704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13705. }
  13706. else if(gunType[gun_index] == 'O')
  13707. {
  13708. tempIndex = gun_index;
  13709. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13710. {
  13711. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13712. {
  13713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13714. }
  13715. }
  13716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13717. }
  13718. else
  13719. {
  13720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13721. {
  13722. tempIndex = 2;
  13723. }
  13724. else
  13725. {
  13726. tempIndex = gun_index;
  13727. }
  13728. for (int index = 0; index < AC_QUANTITY; index++)
  13729. {
  13730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13731. {
  13732. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13733. }
  13734. }// End of for AC_QUANTITY
  13735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13736. }
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13740. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13743. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13744. //idx_sample=2;
  13745. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13746. if(gunType[gun_index] == 'J')
  13747. {
  13748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13749. {
  13750. tempIndex = ((gun_index==2) ? 1: 0);
  13751. }
  13752. else
  13753. {
  13754. tempIndex = gun_index;
  13755. }
  13756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13757. {
  13758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13759. {
  13760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13761. }
  13762. }// END OF CHAdeMO_QUANTITY
  13763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13764. }
  13765. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13766. {
  13767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13768. {
  13769. tempIndex = ((gun_index==2) ? 1: 0);
  13770. }
  13771. else
  13772. {
  13773. tempIndex = gun_index;
  13774. }
  13775. for (int index = 0; index < CCS_QUANTITY; index++)
  13776. {
  13777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13778. {
  13779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13780. }
  13781. }// END OF CCS_QUANTITY
  13782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13783. }
  13784. else if(gunType[gun_index] == 'G')
  13785. {
  13786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13787. {
  13788. tempIndex = ((gun_index==2) ? 1: 0);
  13789. }
  13790. else
  13791. {
  13792. tempIndex = gun_index;
  13793. }
  13794. for (int index = 0; index < GB_QUANTITY; index++)
  13795. {
  13796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13797. {
  13798. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13799. }
  13800. }// END OF GB_QUANTITY
  13801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13802. }
  13803. else if(gunType[gun_index] == 'O')
  13804. {
  13805. tempIndex = gun_index;
  13806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13807. {
  13808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13809. {
  13810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13811. }
  13812. }
  13813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13814. }
  13815. else
  13816. {
  13817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13818. {
  13819. tempIndex = 2;
  13820. }
  13821. else
  13822. {
  13823. tempIndex = gun_index;
  13824. }
  13825. for (int index = 0; index < AC_QUANTITY; index++)
  13826. {
  13827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13828. {
  13829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13830. }
  13831. }// END OF AC_QUANTITY
  13832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13833. }
  13834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13837. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13840. //2.3====================================== Power.Active.Import =========================================
  13841. //idx_sample=3;
  13842. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13843. if(gunType[gun_index] == 'J')
  13844. {
  13845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13846. {
  13847. tempIndex = ((gun_index==2) ? 1: 0);
  13848. }
  13849. else
  13850. {
  13851. tempIndex = gun_index;
  13852. }
  13853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13854. {
  13855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13856. {
  13857. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13858. }
  13859. } // End for CHAdeMO_QUANTITY
  13860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13861. }
  13862. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13863. {
  13864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13865. {
  13866. tempIndex = ((gun_index==2) ? 1: 0);
  13867. }
  13868. else
  13869. {
  13870. tempIndex = gun_index;
  13871. }
  13872. for (int index = 0; index < CCS_QUANTITY; index++)
  13873. {
  13874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13875. {
  13876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13877. }
  13878. } // END for CCS_QUANTITY
  13879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13880. }
  13881. else if(gunType[gun_index] == 'G')
  13882. {
  13883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13884. {
  13885. tempIndex = ((gun_index==2) ? 1: 0);
  13886. }
  13887. else
  13888. {
  13889. tempIndex = gun_index;
  13890. }
  13891. for (int index = 0; index < GB_QUANTITY; index++)
  13892. {
  13893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13894. {
  13895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13896. }
  13897. }// END for GB_QUANTITY
  13898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13899. }
  13900. else if(gunType[gun_index] == 'O')
  13901. {
  13902. tempIndex = gun_index;
  13903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13904. {
  13905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13906. {
  13907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13908. }
  13909. }
  13910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13911. }
  13912. else
  13913. {
  13914. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13915. {
  13916. tempIndex = 2;
  13917. }
  13918. else
  13919. {
  13920. tempIndex = gun_index;
  13921. }
  13922. for (int index = 0; index < AC_QUANTITY; index++)
  13923. {
  13924. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13925. {
  13926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13927. }
  13928. } // END for AC_QUANTITY
  13929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13930. }
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13934. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13937. //2.4====================================== Voltage L1 ====================================================
  13938. //idx_sample=4;
  13939. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13940. if(gunType[gun_index] == 'J')
  13941. {
  13942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13943. {
  13944. tempIndex = ((gun_index==2) ? 1: 0);
  13945. }
  13946. else
  13947. {
  13948. tempIndex = gun_index;
  13949. }
  13950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13951. {
  13952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13953. {
  13954. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13955. }
  13956. } // END OF FOR CHAdeMO_QUANTITY
  13957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13958. }
  13959. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13960. {
  13961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13962. {
  13963. tempIndex = ((gun_index==2) ? 1: 0);
  13964. }
  13965. else
  13966. {
  13967. tempIndex = gun_index;
  13968. }
  13969. for (int index = 0; index < CCS_QUANTITY; index++)
  13970. {
  13971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13972. {
  13973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13974. }
  13975. } // END OF FOR CCS_QUANTITY
  13976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13977. }
  13978. else if(gunType[gun_index] == 'G')
  13979. {
  13980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13981. {
  13982. tempIndex = ((gun_index==2) ? 1: 0);
  13983. }
  13984. else
  13985. {
  13986. tempIndex = gun_index;
  13987. }
  13988. for (int index = 0; index < GB_QUANTITY; index++)
  13989. {
  13990. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13991. {
  13992. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13993. }
  13994. } // END OF FOR GB_QUANTITY
  13995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13996. }
  13997. else if(gunType[gun_index] == 'O')
  13998. {
  13999. tempIndex = gun_index;
  14000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14001. {
  14002. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14003. {
  14004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14005. }
  14006. }
  14007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14008. }
  14009. else
  14010. {
  14011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14012. {
  14013. tempIndex = 2;
  14014. }
  14015. else
  14016. {
  14017. tempIndex = gun_index;
  14018. }
  14019. for (int index = 0; index < AC_QUANTITY; index++)
  14020. {
  14021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14022. {
  14023. 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
  14024. }
  14025. } // END OF FOR AC_QUANTITY
  14026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14027. }
  14028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14031. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14034. //2.5============================================== SoC =========================================================
  14035. //idx_sample=5;
  14036. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14037. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14038. {
  14039. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14040. {
  14041. tempIndex = ((gun_index==2) ? 1: 0);
  14042. }
  14043. else
  14044. {
  14045. tempIndex = gun_index;
  14046. }
  14047. if(gunType[gun_index] == 'J')
  14048. {
  14049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14050. {
  14051. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14052. {
  14053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14054. }
  14055. }
  14056. }
  14057. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14058. {
  14059. for (int index = 0; index < CCS_QUANTITY; index++)
  14060. {
  14061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14062. {
  14063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14064. }
  14065. }
  14066. }
  14067. else if(gunType[gun_index] == 'G')
  14068. {
  14069. for (int index = 0; index < GB_QUANTITY; index++)
  14070. {
  14071. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14072. {
  14073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14074. }
  14075. }
  14076. }
  14077. else if(gunType[gun_index] == 'O')
  14078. {
  14079. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14080. {
  14081. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14082. {
  14083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14084. }
  14085. }
  14086. }
  14087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  14092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14093. } // END FOR DC CASE
  14094. //2.6====================================== Current.Import L2 ==============================================
  14095. // idx_sample=6;
  14096. // AC 3 phase L2 current
  14097. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14098. {
  14099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14100. {
  14101. tempIndex = 2;
  14102. }
  14103. else
  14104. {
  14105. tempIndex = gun_index;
  14106. }
  14107. for (int index = 0; index < AC_QUANTITY; index++)
  14108. {
  14109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14110. {
  14111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14112. }
  14113. }// End of for AC_QUANTITY
  14114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14115. }
  14116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14121. //2.7====================================== Current.Import L3 ==============================================
  14122. // idx_sample=7;
  14123. // AC 3 phase L3 current
  14124. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14125. {
  14126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14127. {
  14128. tempIndex = 2;
  14129. }
  14130. else
  14131. {
  14132. tempIndex = gun_index;
  14133. }
  14134. for (int index = 0; index < AC_QUANTITY; index++)
  14135. {
  14136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14137. {
  14138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14139. }
  14140. }// End of for AC_QUANTITY
  14141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14142. }
  14143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14148. //2.9====================================== Voltage L2 ====================================================
  14149. //idx_sample=8;
  14150. // AC 3 phase L2 volatge
  14151. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14152. {
  14153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14154. {
  14155. tempIndex = 2;
  14156. }
  14157. else
  14158. {
  14159. tempIndex = gun_index;
  14160. }
  14161. for (int index = 0; index < AC_QUANTITY; index++)
  14162. {
  14163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14164. {
  14165. 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
  14166. }
  14167. } // END OF FOR AC_QUANTITY
  14168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14169. }
  14170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14175. //2.10====================================== Voltage L3 ====================================================
  14176. //idx_sample=9;
  14177. // AC 3 phase L3 volatge
  14178. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14179. {
  14180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14181. {
  14182. tempIndex = 2;
  14183. }
  14184. else
  14185. {
  14186. tempIndex = gun_index;
  14187. }
  14188. for (int index = 0; index < AC_QUANTITY; index++)
  14189. {
  14190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14191. {
  14192. 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
  14193. }
  14194. } // END OF FOR AC_QUANTITY
  14195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14196. }
  14197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14202. //======================================== Message create ==============================================
  14203. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14204. {
  14205. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  14206. ,gun_index+1
  14207. ,MESSAGE_TYPE_CALL
  14208. ,guid
  14209. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14210. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14211. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14213. ,"PowerLoss"
  14214. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14215. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14216. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14217. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14218. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14219. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14220. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14221. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14222. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14223. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14224. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14225. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14226. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14227. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14228. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14229. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14230. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14231. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14232. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14233. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14234. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14235. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14236. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14237. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14238. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14239. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14240. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14242. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14243. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  14251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  14252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  14253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  14254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  14255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  14256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  14257. );
  14258. }
  14259. else
  14260. {
  14261. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  14262. {
  14263. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  14264. ,gun_index+1
  14265. ,MESSAGE_TYPE_CALL
  14266. ,guid
  14267. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14268. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14269. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14271. ,"PowerLoss"
  14272. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14292. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14293. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14294. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14295. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14298. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14308. );
  14309. }
  14310. else
  14311. {
  14312. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  14313. ,gun_index+1
  14314. ,MESSAGE_TYPE_CALL
  14315. ,guid
  14316. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14317. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14318. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14320. ,"PowerLoss"
  14321. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14385. );
  14386. }
  14387. }
  14388. // Check File "TempStopTransaction" Exist
  14389. if((access(TempStopTransaction,F_OK))!=-1)
  14390. {
  14391. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14392. fclose(fopen(TempStopTransaction, "w"));
  14393. }
  14394. else
  14395. {
  14396. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14397. FILE *log = fopen(TempStopTransaction, "w+");
  14398. if(log == NULL)
  14399. {
  14400. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14401. return ;
  14402. }
  14403. else
  14404. {
  14405. fclose(log);
  14406. }
  14407. }
  14408. //Add TempStopTransaction | Update TempStopTransaction
  14409. // open file for writing
  14410. FILE *outfile;
  14411. outfile = fopen (TempStopTransaction, "a");
  14412. //DEBUG_INFO("data = %s\n", queuedata);
  14413. fputs(queuedata, outfile);
  14414. fputs("\n", outfile);
  14415. fclose (outfile);
  14416. }
  14417. void checkTempStopTransaction(int gun_index)
  14418. {
  14419. FILE *fptr1;
  14420. char ch;
  14421. char str[QUEUE_MESSAGE_LENGTH]={0};
  14422. char guid[37]={0};
  14423. char tempdata[65]={0};
  14424. char connectorStr[2]={0};
  14425. char TempStopTransaction[256];
  14426. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14427. fptr1 = fopen(TempStopTransaction, "r");
  14428. //TempStopTransaction格式: 槍號,StopTransaction封包
  14429. if (!fptr1)
  14430. {
  14431. //printf(" File not found or unable to open the input file!!\n");
  14432. return ;
  14433. }
  14434. ch=fgetc(fptr1);
  14435. //printf(" Now the content of the file %s is : \n",fname);
  14436. rewind(fptr1);
  14437. if(ch!=EOF)
  14438. {
  14439. // copy all contents to the temporary file except the specific line
  14440. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14441. {
  14442. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14443. if(str[0]=='\0')
  14444. {
  14445. break;
  14446. }
  14447. //TempStopTransaction格式: 槍號,StopTransaction封包
  14448. strncpy(connectorStr, str, 1);
  14449. if(atoi(connectorStr) != (gun_index+1))
  14450. {
  14451. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14452. fclose(fptr1);
  14453. return ;
  14454. }
  14455. //random_uuid(guid);
  14456. strncpy(guid, str+6, 36); //copy guid
  14457. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14458. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14459. {
  14460. DEBUG_INFO("StopTransaction mapitem pass\n");
  14461. }
  14462. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14463. memset(str,0,ARRAY_SIZE(str));
  14464. }
  14465. }
  14466. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14467. fclose(fptr1);
  14468. remove(TempStopTransaction); // remove the original file
  14469. }
  14470. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14471. {
  14472. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14473. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14474. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14475. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14476. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14477. }
  14478. int GetWebSocketPingInterval(void)
  14479. {
  14480. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14481. }
  14482. int GetServerSign(void)
  14483. {
  14484. return server_sign;
  14485. }
  14486. uint8_t GetOcppSecurityProfile()
  14487. {
  14488. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14489. }
  14490. void GetOcppChargerBoxId(uint8_t *data)
  14491. {
  14492. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14493. }
  14494. void GetOcppSecurityPassword(uint8_t *data)
  14495. {
  14496. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14497. }
  14498. void SetServerSign(int value)
  14499. {
  14500. server_sign = value;
  14501. }
  14502. int GetBootNotificationInterval(void)
  14503. {
  14504. return BootNotificationInterval;
  14505. }
  14506. int GetInternetConn(void)
  14507. {
  14508. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14509. }
  14510. void InitialSystemValue(void)
  14511. {
  14512. int connectorIndex = 0;
  14513. //int valueASCII = 0;
  14514. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14515. gunTotalNumber=0;
  14516. SystemInitial = 0;
  14517. localversion=0;
  14518. BootNotificationInterval = 0;
  14519. authorizeRetryTimes = 0;
  14520. GunStatusInterval = 10;
  14521. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14522. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14523. //Hear Beat
  14524. HeartBeatWithNOResponse = 0;
  14525. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14526. FirstHeartBeat = 0;
  14527. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14528. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14529. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14530. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14531. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14532. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14533. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14534. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14535. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14536. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14537. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14538. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14539. memset(gunType, 0, ARRAY_SIZE(gunType));
  14540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14541. {
  14542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='O')
  14543. {
  14544. // DO series
  14545. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14546. {
  14547. SystemInitial = SystemInitial + 1;
  14548. gunTotalNumber = gunTotalNumber + 1;
  14549. gunType[connectorIndex] = 'O';
  14550. connectorIndex = connectorIndex + 1;
  14551. }
  14552. }
  14553. else
  14554. {
  14555. // DM, DW, DS series
  14556. //check connector / socket type (index: 8, 9, 10)
  14557. for(int index=7; index <10 ; index++)
  14558. {
  14559. if(index != 8)
  14560. {
  14561. // DC Connector
  14562. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14563. {
  14564. SystemInitial = SystemInitial + 1;
  14565. gunTotalNumber = gunTotalNumber + 1;
  14566. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14567. connectorIndex = connectorIndex + 1;
  14568. }
  14569. }
  14570. else
  14571. {
  14572. // AC Connector
  14573. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14574. {
  14575. SystemInitial = SystemInitial + 1;
  14576. gunTotalNumber = gunTotalNumber + 1;
  14577. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14578. connectorIndex = connectorIndex + 1;
  14579. }
  14580. }
  14581. }
  14582. }
  14583. //DEBUG_INFO("DC ...\n");
  14584. }
  14585. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14586. {
  14587. //check connector / socket type (index: 8, 9, 10)
  14588. for(int index=7; index <10 ; index++)
  14589. {
  14590. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14591. {
  14592. SystemInitial = SystemInitial + 1;
  14593. gunTotalNumber = gunTotalNumber + 1;
  14594. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14595. connectorIndex = connectorIndex + 1;
  14596. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14597. }
  14598. }
  14599. }
  14600. //Status && ConnectorPlugIn Setting
  14601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14602. {
  14603. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14604. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14605. }
  14606. for (int index = 0; index < CCS_QUANTITY; index++)
  14607. {
  14608. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14609. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14610. }
  14611. for (int index = 0; index < GB_QUANTITY; index++)
  14612. {
  14613. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14614. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14615. }
  14616. for (int index = 0; index < AC_QUANTITY; index++)
  14617. {
  14618. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14619. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14620. }
  14621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14622. {
  14623. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14624. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14625. }
  14626. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14627. {
  14628. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14629. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14630. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14631. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14632. }
  14633. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14634. clientTime.Heartbeat=time((time_t*)NULL);
  14635. sleep(1);
  14636. }
  14637. void LWS_Send(char * str)
  14638. {
  14639. //=====================================================
  14640. // Check InternetConn 0: disconnected, 1: connected
  14641. //====================================================
  14642. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14643. {
  14644. DEBUG_INFO("offline now !!!\n");
  14645. return;
  14646. }
  14647. pthread_mutex_lock(&lock_send);
  14648. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14649. sprintf((char *)SendBuffer, "%s", str);
  14650. SendBufLen = strlen(str);
  14651. pthread_mutex_unlock(&lock_send);
  14652. lws_callback_on_writable(wsi_client);
  14653. //lws_service(context, 0);
  14654. //sleep(1);
  14655. }
  14656. void LWS_SendNow(char * str)
  14657. {
  14658. //=====================================================
  14659. // Check InternetConn 0: disconnected, 1: connected
  14660. //====================================================
  14661. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14662. {
  14663. DEBUG_INFO("offline now !!!\n");
  14664. return;
  14665. }
  14666. pthread_mutex_lock(&lock_send);
  14667. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14668. sprintf((char *)SendBuffer, "%s", str);
  14669. SendBufLen = strlen(str);
  14670. pthread_mutex_unlock(&lock_send);
  14671. lws_callback_on_writable(wsi_client);
  14672. lws_service(context, 0);
  14673. //sleep(1);
  14674. }