MessageHandler.c 628 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181
  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. //===================================
  18. // Define CP State constant
  19. //===================================
  20. #define CP_STATE_UNKNOWN 0
  21. #define CP_STATE_A 1
  22. #define CP_STATE_B 2
  23. #define CP_STATE_C 3
  24. #define CP_STATE_D 4
  25. #define CP_STATE_E 5
  26. #define CP_STATE_F 6
  27. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  28. struct StatusCodeData *ShmStatusCodeData;
  29. struct PsuData *ShmPsuData ;
  30. struct OCPP16Data *ShmOCPP16Data;
  31. #define MACROSTR(k) #k
  32. //ConfigurationMaxKeys
  33. #define GetConfigurationMaxKeysNUM 43
  34. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  35. char queuedata[2600] = {0};
  36. //=================================
  37. // StatusNotification cycle
  38. //=================================
  39. static int server_cycle_Status = 120;
  40. //===============================
  41. // Configuration: unknownkey
  42. //===============================
  43. static char unknownkey[10][20] = {0};
  44. static int UnknownKeynum = 0;
  45. //===============================
  46. // Gun Total Numbers
  47. //===============================
  48. static int gunTotalNumber = 0;
  49. static unsigned char gunType[4] = {0};
  50. //===============================
  51. // Local List Version
  52. //===============================
  53. static int localversion=0;
  54. static char idTagAuthorization[32] = {0};
  55. //===============================
  56. // OCPP sign variable
  57. //===============================
  58. static int server_sign = FALSE;
  59. int server_pending = FALSE;
  60. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  61. static int BootNotificationInterval = 0;
  62. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  63. //===============================
  64. // OCPP auth variable
  65. //===============================
  66. static int authorizeRetryTimes = 0; //number of Retry times
  67. //===============================
  68. // OCPP other variables
  69. //===============================
  70. //int isUpdateRequest = FALSE;
  71. static int HeartBeatWaitTime = 10;
  72. static int FirstHeartBeat = 0;
  73. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  74. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  75. static char CurrentChargingProfileScheduleStr[30] = {0};
  76. //========================================
  77. // OCPP status/previous related variables
  78. //========================================
  79. static int GunStatusInterval = 10;
  80. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  81. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  82. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  83. static int GbPreviousSystemStatus[GB_QUANTITY];
  84. static int AcPreviousSystemStatus[AC_QUANTITY];
  85. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  86. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  87. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  88. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  89. static int TransactionMessageAttemptsValue = 0;
  90. static int TransactionMessageRetryIntervalValue = 0;
  91. static int TempMeterValueInterval = 0;
  92. static struct OCPPAuthLocalElemet
  93. {
  94. int listVersionInt;
  95. char idTagstr[20];
  96. char parentIdTag[20];
  97. char expiryDate[30];
  98. char idTagstatus[16];
  99. }idTagQuery;
  100. //=============================================
  101. // OCPP HeartBeat Response Not Receive Counts
  102. //============================================
  103. static int HeartBeatWithNOResponse = 0;
  104. static int HeartBeatCountPerHour = 0;
  105. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  106. extern int GetTransactionQueueNum(void);
  107. extern struct Charger_Info Charger;
  108. extern sqlite3 *db;
  109. int TransactionMessageAttemptsGet(void);
  110. int TransactionMessageRetryIntervalGet(void);
  111. int GetOcppConnStatus(void);
  112. void SetOcppConnStatus(uint8_t status);
  113. int setKeyValue(char *key, char *value);
  114. void OCPP_get_TableAuthlocalAllData(void);
  115. void processUnkownKey(void);
  116. struct StructOCPPMeterValue
  117. {
  118. unsigned char TimeStamp[28];
  119. struct StructSampledValue SampledValue[10];
  120. };
  121. struct ClientTime
  122. {
  123. unsigned int Heartbeat;
  124. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  125. unsigned int StartTransaction;
  126. unsigned int StopTransaction;
  127. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }clientTime;
  129. typedef union
  130. {
  131. //Operations Initiated by Central System
  132. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  133. struct
  134. {
  135. //CsMsgValue[0]
  136. unsigned char StatusNotificationReq :1; //bit 0,
  137. unsigned char StatusNotificationConf :1; //bit 0,
  138. unsigned char :6; //bit 2~7
  139. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  140. }CpinitiateMsg;
  141. CpinitiateMsg cpinitateMsg;
  142. //==========================================
  143. // Init all Enumeration & Mapping String
  144. //==========================================
  145. /*ChargePointErrorCode*/
  146. typedef enum {
  147. ConnectorLockFailure,
  148. EVCommunicationError,
  149. GroundFailure,
  150. HighTemperature,
  151. InternalError,
  152. LocalListConflict,
  153. NoError,
  154. OtherError,
  155. OverCurrentFailure,
  156. OverVoltage,
  157. PowerMeterFailure,
  158. PowerSwitchFailure,
  159. ReaderFailure,
  160. ResetFailure,
  161. UnderVoltage,
  162. WeakSignal
  163. } ChargePointErrorCode;
  164. #if 0
  165. static char *ChargePointErrorCodeStr[] = {
  166. MACROSTR(ConnectorLockFailure),
  167. MACROSTR(EVCommunicationError),
  168. MACROSTR(GroundFailure),
  169. MACROSTR(HighTemperature),
  170. MACROSTR(InternalError),
  171. MACROSTR(LocalListConflict),
  172. MACROSTR(NoError),
  173. MACROSTR(OtherError),
  174. MACROSTR(OverCurrentFailure),
  175. MACROSTR(OverVoltage),
  176. MACROSTR(PowerMeterFailure),
  177. MACROSTR(PowerSwitchFailure),
  178. MACROSTR(ReaderFailure),
  179. MACROSTR(ResetFailure),
  180. MACROSTR(UnderVoltage),
  181. MACROSTR(WeakSignal)
  182. };
  183. #endif
  184. /*ChargePointStatus*/
  185. typedef enum {
  186. Available =0,
  187. Preparing,
  188. Charging,
  189. SuspendedEVSE,
  190. SuspendedEV,
  191. Finishing,
  192. Reserved,
  193. Unavailable,
  194. Faulted
  195. } ChargePointStatus;
  196. static char * ChargePointStatusStr[] = {
  197. MACROSTR(Available),
  198. MACROSTR(Preparing),
  199. MACROSTR(Charging),
  200. MACROSTR(SuspendedEVSE),
  201. MACROSTR(SuspendedEV),
  202. MACROSTR(Finishing),
  203. MACROSTR(Reserved),
  204. MACROSTR(Unavailable),
  205. MACROSTR(Faulted)
  206. };
  207. /*AvailabilityType*/
  208. typedef enum {
  209. RegistrationStatus_Accepted,
  210. RegistrationStatus_Pending,
  211. RegistrationStatus_Rejected
  212. } RegistrationStatus;
  213. static char *RegistrationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Pending),
  216. MACROSTR(Rejected)
  217. };
  218. /*AvailabilityType*/
  219. typedef enum {
  220. Inoperative,
  221. Operative
  222. } AvailabilityType;
  223. static char *AvailabilityTypeStr[] = {
  224. MACROSTR(Inoperative),
  225. MACROSTR(Operative)
  226. };
  227. /*AvailabilityStatus*/
  228. typedef enum {
  229. Accepted,
  230. Rejected,
  231. Scheduled
  232. } AvailabilityStatus;
  233. static char *AvailabilityStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected),
  236. MACROSTR(Scheduled)
  237. };
  238. /*ConfigurationStatus*/
  239. typedef enum {
  240. ConfigurationStatus_Accepted,
  241. ConfigurationStatus_Rejected,
  242. RebootRequired,
  243. NotSupported
  244. } ConfigurationStatus;
  245. static char *ConfigurationStatusStr[] = {
  246. MACROSTR(Accepted),
  247. MACROSTR(Rejected),
  248. MACROSTR(RebootRequired),
  249. MACROSTR(NotSupported)
  250. };
  251. /*ClearCacheStatus*/
  252. typedef enum {
  253. ClearCacheStatus_Accepted,
  254. ClearCacheStatus_Rejected
  255. } ClearCacheStatus;
  256. static char *ClearCacheStatusStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected)
  259. };
  260. /*ChargingProfilePurposeType*/
  261. typedef enum {
  262. ChargePointMaxProfile,
  263. TxDefaultProfile,
  264. TxProfile
  265. } ChargingProfilePurposeType;
  266. static char *ChargingProfilePurposeTypeStr[] = {
  267. MACROSTR(ChargePointMaxProfile),
  268. MACROSTR(TxDefaultProfile),
  269. MACROSTR(TxProfile)
  270. };
  271. /*ChargingProfileStatus*/
  272. typedef enum {
  273. ChargingProfileStatus_Accepted,
  274. ChargingProfileStatus_Rejected,
  275. ChargingProfileStatus_NotSupported
  276. } ChargingProfileStatus;
  277. static char *ChargingProfileStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected),
  280. MACROSTR(NotSupported)
  281. };
  282. /*ClearChargingProfileStatus*/
  283. typedef enum {
  284. ClearChargingProfileStatus_Accepted,
  285. ClearChargingProfileStatus_Unknown
  286. } ClearChargingProfileStatus;
  287. static char *ClearChargingProfileStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Unknown)
  290. };
  291. /*GetCompositeScheduleStatus*/
  292. typedef enum {
  293. GetCompositeScheduleStatus_Accepted,
  294. GetCompositeScheduleStatus_Rejected
  295. } GetCompositeScheduleStatus;
  296. static char *GetCompositeScheduleStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected)
  299. };
  300. /*ChargingRateUnitType*/
  301. typedef enum {
  302. ChargingRateUnitType_W,
  303. ChargingRateUnitType_A
  304. } ChargingRateUnitType;
  305. /*AuthorizationStatus*/
  306. typedef enum {
  307. AuthorizationStatus_Accepted ,
  308. AuthorizationStatus_Blocked ,
  309. AuthorizationStatus_Expired ,
  310. AuthorizationStatus_Invalid ,
  311. AuthorizationStatus_ConcurrentTx
  312. } AuthorizationStatus;
  313. /*UpdateType*/
  314. typedef enum {
  315. Differential ,
  316. Full
  317. } UpdateType;
  318. static char *UpdateTypeStr[] = {
  319. MACROSTR(Differential),
  320. MACROSTR(Full)
  321. };
  322. /*UpdateStatus*/
  323. typedef enum {
  324. UpdateStatus_Accepted ,
  325. UpdateStatus_Failed ,
  326. UpdateStatus_NotSupported ,
  327. UpdateStatus_VersionMismatch
  328. } UpdateStatus;
  329. static char *UpdateStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Failed),
  332. MACROSTR(NotSupported),
  333. MACROSTR(VersionMismatch)
  334. };
  335. /*RemoteStartStopStatus*/
  336. typedef enum {
  337. RemoteStartStopStatus_Accepted,
  338. RemoteStartStopStatus_Rejected
  339. } RemoteStartStopStatus;
  340. static char *RemoteStartStopStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Rejected)
  343. };
  344. /*ReservationStatus*/
  345. typedef enum {
  346. ReservationStatus_Accepted,
  347. ReservationStatus_Faulted,
  348. ReservationStatus_Occupied,
  349. ReservationStatus_Rejected,
  350. ReservationStatus_Unavailable
  351. } ReservationStatus;
  352. static char *ReservationStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Faulted),
  355. MACROSTR(Occupied),
  356. MACROSTR(Rejected),
  357. MACROSTR(Unavailable)
  358. };
  359. /*ResetType*/
  360. typedef enum {
  361. Hard,
  362. Soft
  363. } ResetType;
  364. static char *ResetTypeStr[] = {
  365. MACROSTR(Hard),
  366. MACROSTR(Soft)
  367. };
  368. /*ResetStatus*/
  369. typedef enum {
  370. ResetStatus_Accepted,
  371. ResetStatus_Rejected
  372. } ResetStatus;
  373. static char *ResetStatusStr[] = {
  374. MACROSTR(Accepted),
  375. MACROSTR(Rejected)
  376. };
  377. /*DiagnosticsStatus*/
  378. typedef enum {
  379. DiagnosticsStatus_Idle,
  380. DiagnosticsStatus_Uploaded,
  381. DiagnosticsStatus_UploadFailed,
  382. DiagnosticsStatus_Uploading
  383. } DiagnosticsStatus;
  384. static char * DiagnosticsStatusStr[] = {
  385. MACROSTR(Idle),
  386. MACROSTR(Uploaded),
  387. MACROSTR(UploadFailed),
  388. MACROSTR(Uploading)
  389. };
  390. /*FirmwareStatus*/
  391. typedef enum {
  392. FirmwareStatus_Downloaded,
  393. FirmwareStatus_DownloadFailed,
  394. FirmwareStatus_Downloading,
  395. FirmwareStatus_Idle,
  396. FirmwareStatus_InstallationFailed,
  397. FirmwareStatus_Installing,
  398. FirmwareStatus_Installed
  399. } FirmwareStatus;
  400. static char * FirmwareStatusStr[] = {
  401. MACROSTR(Downloaded),
  402. MACROSTR(DownloadFailed),
  403. MACROSTR(Downloading),
  404. MACROSTR(Idle),
  405. MACROSTR(InstallationFailed),
  406. MACROSTR(Installing),
  407. MACROSTR(Installed)
  408. };
  409. /*MessageTrigger*/
  410. typedef enum {
  411. BootNotification,
  412. DiagnosticsStatusNotification,
  413. FirmwareStatusNotification,
  414. Heartbeat,
  415. MeterValues,
  416. StatusNotification
  417. } MessageTrigger;
  418. static char * MessageTriggerStr[] = {
  419. MACROSTR(BootNotification),
  420. MACROSTR(DiagnosticsStatusNotification),
  421. MACROSTR(FirmwareStatusNotification),
  422. MACROSTR(Heartbeat),
  423. MACROSTR(MeterValues),
  424. MACROSTR(StatusNotification)
  425. };
  426. /*TriggerMessageStatus*/
  427. typedef enum {
  428. TriggerMessageStatus_Accepted ,
  429. TriggerMessageStatus_Rejected ,
  430. TriggerMessageStatus_NotImplemented
  431. } TriggerMessageStatus;
  432. static char * TriggerMessageStatusStr[] = {
  433. MACROSTR(Accepted),
  434. MACROSTR(Rejected),
  435. MACROSTR(NotImplemented)
  436. };
  437. /*UnlockStatus*/
  438. typedef enum {
  439. Unlocked,
  440. UnlockFailed,
  441. UnlockStatus_NotSupported
  442. } UnlockStatus;
  443. static char * UnlockStatusStr[] = {
  444. MACROSTR(Unlocked),
  445. MACROSTR(UnlockFailed),
  446. MACROSTR(NotSupported)
  447. };
  448. /*StopTransactionReason*/
  449. typedef enum {
  450. EmergencyStop,
  451. EVDisconnected,
  452. HardReset,
  453. Local,
  454. Other,
  455. PowerLoss,
  456. Reboot,
  457. Remote,
  458. SoftReset,
  459. UnlockCommand,
  460. DeAuthorized
  461. } StopTransactionReason;
  462. #if 0
  463. static char * StopTransactionReasonStr[] = {
  464. MACROSTR(EmergencyStop),
  465. MACROSTR(EVDisconnected),
  466. MACROSTR(HardReset),
  467. MACROSTR(Local),
  468. MACROSTR(Other),
  469. MACROSTR(PowerLoss),
  470. MACROSTR(Reboot),
  471. MACROSTR(Remote),
  472. MACROSTR(SoftReset),
  473. MACROSTR(UnlockCommand),
  474. MACROSTR(DeAuthorized)
  475. };
  476. #endif
  477. /*CancelReservationStatus*/
  478. typedef enum {
  479. CancelReservationStatus_Accepted,
  480. CancelReservationStatus_Rejected
  481. } CancelReservationStatus;
  482. static char * CancelReservationStatusStr[] = {
  483. MACROSTR(Accepted),
  484. MACROSTR(Rejected)
  485. };
  486. /*ReadingContext*/
  487. typedef enum {
  488. ReadingContext_Interruption_Begin,
  489. ReadingContext_Interruption_End,
  490. ReadingContext_Other,
  491. ReadingContext_Sample_Clock,
  492. ReadingContext_Sample_Periodic ,
  493. ReadingContext_Transaction_Begin ,
  494. ReadingContext_Transaction_End,
  495. ReadingContext_Trigger
  496. } ReadingContext;
  497. static char * ReadingContextStr[] = {
  498. MACROSTR(Interruption.Begin),
  499. MACROSTR(Interruption.End),
  500. MACROSTR(Other),
  501. MACROSTR(Sample.Clock),
  502. MACROSTR(Sample.Periodic),
  503. MACROSTR(Transaction.Begin),
  504. MACROSTR(Transaction.End),
  505. MACROSTR(Trigger)
  506. };
  507. /*ValueFormat*/
  508. typedef enum {
  509. Raw,
  510. SignedData
  511. } ValueFormat;
  512. static char * ValueFormatStr[] = {
  513. MACROSTR(Raw),
  514. MACROSTR(SignedData)
  515. };
  516. /*Measurand*/
  517. typedef enum {
  518. Current_Export ,
  519. Current_Import,
  520. Current_Offered,
  521. Energy_Active_Export_Register,
  522. Energy_Active_Import_Register,
  523. Energy_Reactive_Export_Register,
  524. Energy_Reactive_Import_Register,
  525. Energy_Active_Export_Interval,
  526. Energy_Active_Import_Interval,
  527. Energy_Reactive_Export_Interval,
  528. Energy_Reactive_Import_Interval,
  529. Frequency,
  530. Power_Active_Export ,
  531. Power_Active_Import,
  532. Power_Factor,
  533. Power_Offered,
  534. Power_Reactive_Export,
  535. Power_Reactive_Import,
  536. RPM,
  537. SoC,
  538. Temperature ,
  539. Voltage
  540. } Measurand;
  541. static char * MeasurandStr[] = {
  542. MACROSTR(Current.Export),
  543. MACROSTR(Current.Import),
  544. MACROSTR(Current.Offered),
  545. MACROSTR(Energy.Active.Export.Register),
  546. MACROSTR(Energy.Active.Import.Register),
  547. MACROSTR(Energy.Reactive.Export.Register),
  548. MACROSTR(Energy.Reactive.Import.Register),
  549. MACROSTR(Energy.Active.Export.Interval),
  550. MACROSTR(Energy.Active.Import.Interval),
  551. MACROSTR(Energy.Reactive.Export.Interval),
  552. MACROSTR(Energy.Reactive.Import.Interval),
  553. MACROSTR(Frequency),
  554. MACROSTR(Power.Active.Export),
  555. MACROSTR(Power.Active.Import),
  556. MACROSTR(Power.Factor),
  557. MACROSTR(Power.Offered),
  558. MACROSTR(Power.Reactive.ExportMACROSTR),
  559. MACROSTR(Power.Reactive.Import),
  560. MACROSTR(RPM),
  561. MACROSTR(SoC),
  562. MACROSTR(Temperature),
  563. MACROSTR(Voltage)
  564. };
  565. /*Location*/
  566. typedef enum {
  567. Location_Body,
  568. Location_Cable,
  569. Location_EV,
  570. Location_Inlet ,
  571. Location_Outlet
  572. } Location;
  573. static char * LocationStr[] = {
  574. MACROSTR(Body),
  575. MACROSTR(Cable),
  576. MACROSTR(EV),
  577. MACROSTR(Inlet),
  578. MACROSTR(Outlet)
  579. };
  580. /*Phase*/
  581. typedef enum {
  582. L1,
  583. L2,
  584. L3,
  585. N,
  586. L1_N,
  587. L2_N,
  588. L3_N,
  589. L1_L2,
  590. L2_L3,
  591. L3_L1
  592. } Phase;
  593. static char * PhaseStr[] = {
  594. MACROSTR(L1),
  595. MACROSTR(L2),
  596. MACROSTR(L3),
  597. MACROSTR(N),
  598. MACROSTR(L1-N),
  599. MACROSTR(L2-N),
  600. MACROSTR(L3-N),
  601. MACROSTR(L1-L2),
  602. MACROSTR(L2-L3),
  603. MACROSTR(L3-L1)
  604. };
  605. /*UnitOfMeasure*/
  606. typedef enum {
  607. UnitOfMeasure_Wh,
  608. UnitOfMeasure_kWh ,
  609. UnitOfMeasure_varh ,
  610. UnitOfMeasure_kvarh ,
  611. UnitOfMeasure_W ,
  612. UnitOfMeasure_kW ,
  613. UnitOfMeasure_VA ,
  614. UnitOfMeasure_kVA ,
  615. UnitOfMeasure_var ,
  616. UnitOfMeasure_kvar ,
  617. UnitOfMeasure_A ,
  618. UnitOfMeasure_V ,
  619. UnitOfMeasure_Celsius ,
  620. UnitOfMeasure_Fahrenheit ,
  621. UnitOfMeasure_K ,
  622. UnitOfMeasure_Percent
  623. } UnitOfMeasure;
  624. static char * UnitOfMeasureStr[] = {
  625. MACROSTR(Wh),
  626. MACROSTR(kWh),
  627. MACROSTR(varh),
  628. MACROSTR(kvarh),
  629. MACROSTR(W),
  630. MACROSTR(kW),
  631. MACROSTR(VA),
  632. MACROSTR(kVA),
  633. MACROSTR(var),
  634. MACROSTR(kvar),
  635. MACROSTR(A),
  636. MACROSTR(V),
  637. MACROSTR(Celsius),
  638. MACROSTR(Fahrenheit),
  639. MACROSTR(K),
  640. MACROSTR(Percent)
  641. };
  642. enum LocalAuthListManagementProfile{
  643. LocalAuthListEnabled=0,
  644. LocalAuthListMaxLength,
  645. SendLocalListMaxLength,
  646. _LocalAuthListManagementProfile_CNT
  647. };
  648. enum ReservationProfile{
  649. ReserveConnectorZeroSupported
  650. };
  651. enum SmartChargingProfile{
  652. ChargeProfileMaxStackLevel,
  653. ChargingScheduleAllowedChargingRateUnit,
  654. ChargingScheduleMaxPeriods,
  655. ConnectorSwitch3to1PhaseSupported,
  656. MaxChargingProfilesInstalled
  657. };
  658. enum ChargerSystemStatus{
  659. ChargerSystemStatus_Booting,
  660. ChargerSystemStatus_Idle,
  661. ChargerSystemStatus_Authorizing,
  662. ChargerSystemStatus_Preparing,
  663. ChargerSystemStatus_Charging,
  664. ChargerSystemStatus_Terminating,
  665. ChargerSystemStatus_Alarm,
  666. ChargerSystemStatus_Fault
  667. };
  668. enum GetConfigurationKey {
  669. GetConfiguration_AllowOfflineTxForUnknownId=0,
  670. GetConfiguration_AuthorizationCacheEnabled,
  671. GetConfiguration_AuthorizeRemoteTxRequests,
  672. GetConfiguration_BlinkRepeat,
  673. GetConfiguration_ClockAlignedDataInterval,
  674. GetConfiguration_ConnectionTimeOut,
  675. GetConfiguration_GetConfigurationMaxKeys,
  676. GetConfiguration_HeartbeatInterval,
  677. GetConfiguration_LightIntensity,
  678. GetConfiguration_LocalAuthorizeOffline,
  679. GetConfiguration_LocalPreAuthorize,
  680. GetConfiguration_MaxEnergyOnInvalidId,
  681. GetConfiguration_MeterValuesAlignedData,
  682. GetConfiguration_MeterValuesAlignedDataMaxLength,
  683. GetConfiguration_MeterValuesSampledData,
  684. GetConfiguration_MeterValuesSampledDataMaxLength,
  685. GetConfiguration_MeterValueSampleInterval,
  686. GetConfiguration_MinimumStatusDuration,
  687. GetConfiguration_NumberOfConnectors,
  688. GetConfiguration_ResetRetries,
  689. GetConfiguration_ConnectorPhaseRotation,
  690. GetConfiguration_ConnectorPhaseRotationMaxLength,
  691. GetConfiguration_StopTransactionOnEVSideDisconnect,
  692. GetConfiguration_StopTransactionOnInvalidId,
  693. GetConfiguration_StopTxnAlignedData,
  694. GetConfiguration_StopTxnAlignedDataMaxLength,
  695. GetConfiguration_StopTxnSampledData,
  696. GetConfiguration_StopTxnSampledDataMaxLength,
  697. GetConfiguration_SupportedFeatureProfiles,
  698. GetConfiguration_SupportedFeatureProfilesMaxLength,
  699. GetConfiguration_TransactionMessageAttempts,
  700. GetConfiguration_TransactionMessageRetryInterval,
  701. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  702. GetConfiguration_WebSocketPingInterval,
  703. GetConfiguration_LocalAuthListEnabled,
  704. GetConfiguration_LocalAuthListMaxLength,
  705. GetConfiguration_SendLocalListMaxLength,
  706. GetConfiguration_ReserveConnectorZeroSupported,
  707. GetConfiguration_ChargeProfileMaxStackLevel,
  708. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  709. GetConfiguration_ChargingScheduleMaxPeriods,
  710. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  711. GetConfiguration_MaxChargingProfilesInstalled,
  712. };
  713. //GetConfiguration Array
  714. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  715. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  717. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  718. //==========================================
  719. // Check time passed since today
  720. //==========================================
  721. long long DiffTimebWithNow(struct timeb ST)
  722. {
  723. //return milli-second
  724. struct timeb ET;
  725. long long StartTime,StopTime;
  726. ftime(&ET);
  727. StartTime=(long long)ST.time;
  728. StopTime=(long long)ET.time;
  729. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  730. }
  731. int getTimePassSinceToday()
  732. {
  733. int result = -1;
  734. time_t t;
  735. struct tm *tmStartToday;
  736. struct timeb tbStartToday;
  737. t=time(NULL);
  738. tmStartToday=localtime(&t);
  739. tmStartToday->tm_hour = 0;
  740. tmStartToday->tm_min = 0;
  741. tmStartToday->tm_sec = 0;
  742. tbStartToday.time = mktime(tmStartToday);
  743. tbStartToday.millitm = 0;
  744. result = DiffTimebWithNow(tbStartToday)/1000;
  745. return result;
  746. }
  747. //==========================================
  748. // GetCompositeSchedule logic related function
  749. //==========================================
  750. int DiffTimebSec(struct timeb ST, struct timeb ET)
  751. {
  752. //return milli-second
  753. unsigned int StartTime,StopTime;
  754. StartTime=(unsigned int)ST.time;
  755. StopTime=(unsigned int)ET.time;
  756. return (StopTime-StartTime);
  757. }
  758. int DiffTimebWithNowSec(struct timeb ST)
  759. {
  760. //return milli-second
  761. struct timeb ET;
  762. unsigned int StartTime,StopTime;
  763. ftime(&ET);
  764. StartTime=(unsigned int)ST.time;
  765. StopTime=(unsigned int)ET.time;
  766. return (StopTime-StartTime);
  767. }
  768. int getStartStop(uint8_t *start, uint8_t *stop)
  769. {
  770. int result = -1;
  771. struct tm tmStart;
  772. struct timeb tbStart;
  773. struct tm tmStop;
  774. struct timeb tbStop;
  775. 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) &&
  776. (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))
  777. {
  778. tmStart.tm_year -= 1900;
  779. tmStart.tm_mon -= 1;
  780. tbStart.time = mktime(&tmStart);
  781. tbStart.millitm = 0;
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStart, tbStop);
  787. }
  788. else
  789. {
  790. DEBUG_WARN("Start or stop date parsing error.\r\n");
  791. }
  792. return result;
  793. }
  794. int getStartSinceToday(uint8_t *stop)
  795. {
  796. int result = -1;
  797. time_t t;
  798. struct tm *tmStartToday;
  799. struct timeb tbStartToday;
  800. struct tm tmStop;
  801. struct timeb tbStop;
  802. if((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))
  803. {
  804. t=time(NULL);
  805. tmStartToday=localtime(&t);
  806. tmStartToday->tm_hour = 0;
  807. tmStartToday->tm_min = 0;
  808. tmStartToday->tm_sec = 0;
  809. tbStartToday.time = mktime(tmStartToday);
  810. tmStop.tm_year -= 1900;
  811. tmStop.tm_mon -= 1;
  812. tbStop.time = mktime(&tmStop);
  813. tbStop.millitm = 0;
  814. result = DiffTimebSec(tbStartToday, tbStop);
  815. }
  816. return result;
  817. }
  818. int getStartSinceWeek(uint8_t *stop)
  819. {
  820. int result = -1;
  821. time_t t;
  822. struct tm *tmStartWeek;
  823. struct timeb tbStartWeek;
  824. struct tm tmStop;
  825. struct timeb tbStop;
  826. if((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))
  827. {
  828. t=time(NULL);
  829. tmStartWeek=localtime(&t);
  830. t-=86400*tmStartWeek->tm_wday;
  831. tmStartWeek=localtime(&t);
  832. tmStartWeek->tm_hour = 0;
  833. tmStartWeek->tm_min = 0;
  834. tmStartWeek->tm_sec = 0;
  835. tbStartWeek.time = mktime(tmStartWeek);
  836. tmStop.tm_year -= 1900;
  837. tmStop.tm_mon -= 1;
  838. tbStop.time = mktime(&tmStop);
  839. tbStop.millitm = 0;
  840. result = DiffTimebSec(tbStartWeek, tbStop);
  841. }
  842. return result;
  843. }
  844. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  845. {
  846. FILE *fp;
  847. char profileFileName[128];
  848. char *line = NULL;
  849. size_t len = 0;
  850. time_t CurrentTime;
  851. struct tm *tmComposite;
  852. struct StructChargingProfile maxProfile;
  853. struct StructChargingProfile defaultTxProfile;
  854. struct StructChargingProfile txProfile;
  855. struct StructChargingSchedulePeriod tmpPeriod;
  856. uint8_t limitMax=0;
  857. uint8_t limitDef=0;
  858. uint8_t limitTx=0;
  859. int compositePeriodIdx = 0;
  860. CurrentTime = time(NULL);
  861. tmComposite=localtime(&CurrentTime);
  862. 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);
  863. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  864. compositeProfile->ChargingSchedule.Duration = durationReq;
  865. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  866. {
  867. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  868. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  869. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  870. }
  871. compositeProfile->ChargingProfileId = 1;
  872. compositeProfile->StackLevel = 99 ;
  873. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  874. maxProfile.ChargingProfileId = -1;
  875. defaultTxProfile.ChargingProfileId = -1;
  876. txProfile.ChargingProfileId = -1;
  877. system("yes|rm /tmp/*.json");
  878. system("cp /Storage/OCPP/*.json /tmp");
  879. /*
  880. * Search valid charging profile
  881. */
  882. //DEBUG_INFO("====================================\n");
  883. // Search max profile
  884. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  885. if((access(profileFileName, F_OK))!=-1)
  886. {
  887. fp = fopen(profileFileName, "r");
  888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  889. {
  890. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  893. }
  894. maxProfile.ChargingProfileId = -1;
  895. maxProfile.StackLevel = -1;
  896. while(getline(&line, &len, fp) != -1)
  897. {
  898. json_object *obj = NULL;
  899. obj = json_tokener_parse(line);
  900. if(is_error(obj))
  901. {
  902. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  903. }
  904. else
  905. {
  906. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  907. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  908. )
  909. {
  910. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  911. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  912. )
  913. {
  914. struct tm tmFrom, tmTo;
  915. struct timeb tbFrom, tbTo;
  916. 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) &&
  917. (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))
  918. {
  919. tmFrom.tm_year -= 1900;
  920. tmFrom.tm_mon -= 1;
  921. tbFrom.time = mktime(&tmFrom);
  922. tmTo.tm_year -= 1900;
  923. tmTo.tm_mon -= 1;
  924. tbTo.time = mktime(&tmTo);
  925. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  926. {
  927. if(maxProfile.ChargingProfileId == -1)
  928. DEBUG_INFO("MaxProfile found.\n");
  929. else
  930. DEBUG_INFO("MaxProfile updated.\n");
  931. // Required item
  932. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  933. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  934. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  935. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  936. 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++)
  937. {
  938. 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"));
  939. 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")));
  940. 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?
  941. 3:
  942. 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")));
  943. }
  944. // Optional item
  945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  946. {
  947. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  948. }
  949. else
  950. {
  951. sprintf((char*)maxProfile.ValidFrom, " ");
  952. }
  953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  954. {
  955. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  956. }
  957. else
  958. {
  959. sprintf((char*)maxProfile.ValidTo, " ");
  960. }
  961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  962. {
  963. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  964. }
  965. else
  966. {
  967. sprintf((char*)maxProfile.RecurrencyKind, " ");
  968. }
  969. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  970. {
  971. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  972. }
  973. else
  974. {
  975. maxProfile.TransactionId = -1;
  976. }
  977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  978. {
  979. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  980. }
  981. else
  982. {
  983. maxProfile.ChargingSchedule.Duration = -1;
  984. }
  985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  986. {
  987. 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")));
  988. }
  989. else
  990. {
  991. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  992. }
  993. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  994. {
  995. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  996. }
  997. else
  998. {
  999. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1000. }
  1001. }
  1002. }
  1003. }
  1004. else
  1005. {
  1006. if(maxProfile.ChargingProfileId == -1)
  1007. DEBUG_INFO("MaxProfile found.\n");
  1008. else
  1009. DEBUG_INFO("MaxProfile updated.\n");
  1010. // Required item
  1011. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1012. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1013. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1014. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1015. 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++)
  1016. {
  1017. 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"));
  1018. 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")));
  1019. 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?
  1020. 3:
  1021. 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")));
  1022. }
  1023. // Optional item
  1024. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1025. {
  1026. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1027. }
  1028. else
  1029. {
  1030. sprintf((char*)maxProfile.ValidFrom, " ");
  1031. }
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. {
  1034. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)maxProfile.ValidTo, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1041. {
  1042. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1049. {
  1050. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1051. }
  1052. else
  1053. {
  1054. maxProfile.TransactionId = -1;
  1055. }
  1056. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1057. {
  1058. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1059. }
  1060. else
  1061. {
  1062. maxProfile.ChargingSchedule.Duration = -1;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1065. {
  1066. 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")));
  1067. }
  1068. else
  1069. {
  1070. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1073. {
  1074. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1075. }
  1076. else
  1077. {
  1078. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. json_object_put(obj);
  1084. }
  1085. fclose(fp);
  1086. /*
  1087. if(maxProfile.ChargingProfileId !=-1)
  1088. {
  1089. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1090. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1091. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1092. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1093. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1094. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1095. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1096. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1097. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1098. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1099. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1101. {
  1102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1103. {
  1104. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1105. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1106. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1107. }
  1108. }
  1109. }
  1110. else
  1111. DEBUG_INFO("MaxProfile not found.\n");
  1112. DEBUG_INFO("------------------------------------\n");*/
  1113. }
  1114. // Search default tx profile
  1115. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1116. if((access(profileFileName, F_OK))==-1)
  1117. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1118. if((access(profileFileName, F_OK))!=-1)
  1119. {
  1120. fp = fopen(profileFileName, "r");
  1121. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1122. {
  1123. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1124. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1125. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1126. }
  1127. defaultTxProfile.ChargingProfileId = -1;
  1128. defaultTxProfile.StackLevel = -1;
  1129. while(getline(&line, &len, fp) != -1)
  1130. {
  1131. json_object *obj = NULL;
  1132. obj = json_tokener_parse(line);
  1133. if(is_error(obj))
  1134. {
  1135. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1136. }
  1137. else
  1138. {
  1139. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1140. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1141. )
  1142. {
  1143. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1144. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1145. )
  1146. {
  1147. struct tm tmFrom, tmTo;
  1148. struct timeb tbFrom, tbTo;
  1149. 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) &&
  1150. (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))
  1151. {
  1152. tmFrom.tm_year -= 1900;
  1153. tmFrom.tm_mon -= 1;
  1154. tbFrom.time = mktime(&tmFrom);
  1155. tmTo.tm_year -= 1900;
  1156. tmTo.tm_mon -= 1;
  1157. tbTo.time = mktime(&tmTo);
  1158. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1159. {
  1160. if(defaultTxProfile.ChargingProfileId == -1)
  1161. DEBUG_INFO("TxDefaultProfile found.\n");
  1162. else
  1163. DEBUG_INFO("TxDefaultProfile updated.\n");
  1164. // Required item
  1165. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1166. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1167. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1168. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1169. 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++)
  1170. {
  1171. 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"));
  1172. 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")));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. }
  1177. // Optional item
  1178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1179. {
  1180. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1181. }
  1182. else
  1183. {
  1184. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1185. }
  1186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1189. }
  1190. else
  1191. {
  1192. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1193. }
  1194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1195. {
  1196. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1201. }
  1202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1203. {
  1204. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1205. }
  1206. else
  1207. {
  1208. defaultTxProfile.TransactionId = -1;
  1209. }
  1210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1211. {
  1212. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1213. }
  1214. else
  1215. {
  1216. defaultTxProfile.ChargingSchedule.Duration = -1;
  1217. }
  1218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1219. {
  1220. 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")));
  1221. }
  1222. else
  1223. {
  1224. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1225. }
  1226. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1227. {
  1228. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1229. }
  1230. else
  1231. {
  1232. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. else
  1238. {
  1239. if(defaultTxProfile.ChargingProfileId == -1)
  1240. DEBUG_INFO("TxDefaultProfile found.\n");
  1241. else
  1242. DEBUG_INFO("TxDefaultProfile updated.\n");
  1243. // Required item
  1244. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1245. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1246. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1247. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1248. 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++)
  1249. {
  1250. 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"));
  1251. 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")));
  1252. 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?
  1253. 3:
  1254. 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")));
  1255. }
  1256. // Optional item
  1257. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1258. {
  1259. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1260. }
  1261. else
  1262. {
  1263. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1264. }
  1265. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1266. {
  1267. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1268. }
  1269. else
  1270. {
  1271. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1272. }
  1273. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1274. {
  1275. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1276. }
  1277. else
  1278. {
  1279. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1280. }
  1281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1282. {
  1283. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1284. }
  1285. else
  1286. {
  1287. defaultTxProfile.TransactionId = -1;
  1288. }
  1289. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1290. {
  1291. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1292. }
  1293. else
  1294. {
  1295. defaultTxProfile.ChargingSchedule.Duration = -1;
  1296. }
  1297. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1298. {
  1299. 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")));
  1300. }
  1301. else
  1302. {
  1303. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1304. }
  1305. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1306. {
  1307. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1308. }
  1309. else
  1310. {
  1311. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. json_object_put(obj);
  1317. }
  1318. fclose(fp);
  1319. /*
  1320. if(defaultTxProfile.ChargingProfileId != -1)
  1321. {
  1322. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1323. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1324. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1325. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1326. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1327. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1328. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1329. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1330. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1331. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1332. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1333. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1334. {
  1335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1336. {
  1337. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1338. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1339. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1340. }
  1341. }
  1342. }
  1343. else
  1344. DEBUG_INFO("TxDefaultProfile not found.\n");
  1345. DEBUG_INFO("------------------------------------\n");*/
  1346. }
  1347. // Search tx profile
  1348. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1349. if((access(profileFileName, F_OK))!=-1)
  1350. {
  1351. fp = fopen(profileFileName, "r");
  1352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1353. {
  1354. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1355. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1356. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1357. }
  1358. txProfile.ChargingProfileId = -1;
  1359. txProfile.StackLevel = -1;
  1360. while(getline(&line, &len, fp) != -1)
  1361. {
  1362. json_object *obj = NULL;
  1363. obj = json_tokener_parse(line);
  1364. if(is_error(obj))
  1365. {
  1366. DEBUG_ERROR("Parse txProfile from file error.\n");
  1367. }
  1368. else
  1369. {
  1370. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1371. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1372. )
  1373. {
  1374. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1375. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1376. )
  1377. {
  1378. struct tm tmFrom, tmTo;
  1379. struct timeb tbFrom, tbTo;
  1380. 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) &&
  1381. (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))
  1382. {
  1383. tmFrom.tm_year -= 1900;
  1384. tmFrom.tm_mon -= 1;
  1385. tbFrom.time = mktime(&tmFrom);
  1386. tmTo.tm_year -= 1900;
  1387. tmTo.tm_mon -= 1;
  1388. tbTo.time = mktime(&tmTo);
  1389. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1390. {
  1391. if(txProfile.ChargingProfileId == -1)
  1392. DEBUG_INFO("TxProfile found.\n");
  1393. else
  1394. DEBUG_INFO("TxProfile updated.\n");
  1395. // Required item
  1396. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1397. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1398. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1399. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1400. 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++)
  1401. {
  1402. 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"));
  1403. 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")));
  1404. 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?
  1405. 3:
  1406. 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")));
  1407. }
  1408. // Optional item
  1409. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1410. {
  1411. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1412. }
  1413. else
  1414. {
  1415. sprintf((char*)txProfile.ValidFrom, " ");
  1416. }
  1417. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1418. {
  1419. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1420. }
  1421. else
  1422. {
  1423. sprintf((char*)txProfile.ValidTo, " ");
  1424. }
  1425. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1426. {
  1427. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1428. }
  1429. else
  1430. {
  1431. sprintf((char*)txProfile.RecurrencyKind, " ");
  1432. }
  1433. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1434. {
  1435. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1436. }
  1437. else
  1438. {
  1439. txProfile.TransactionId = -1;
  1440. }
  1441. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1442. {
  1443. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1444. }
  1445. else
  1446. {
  1447. txProfile.ChargingSchedule.Duration = -1;
  1448. }
  1449. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1450. {
  1451. 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")));
  1452. }
  1453. else
  1454. {
  1455. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1456. }
  1457. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1458. {
  1459. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1460. }
  1461. else
  1462. {
  1463. txProfile.ChargingSchedule.MinChargingRate = -1;
  1464. }
  1465. }
  1466. }
  1467. }
  1468. else
  1469. {
  1470. if(txProfile.ChargingProfileId == -1)
  1471. DEBUG_INFO("TxProfile found.\n");
  1472. else
  1473. DEBUG_INFO("TxProfile updated.\n");
  1474. // Required item
  1475. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1476. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1477. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1478. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1479. 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++)
  1480. {
  1481. 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"));
  1482. 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")));
  1483. 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?
  1484. 3:
  1485. 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")));
  1486. }
  1487. // Optional item
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1489. {
  1490. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)txProfile.ValidFrom, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. {
  1498. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1499. }
  1500. else
  1501. {
  1502. sprintf((char*)txProfile.ValidTo, " ");
  1503. }
  1504. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1505. {
  1506. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1507. }
  1508. else
  1509. {
  1510. sprintf((char*)txProfile.RecurrencyKind, " ");
  1511. }
  1512. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1513. {
  1514. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1515. }
  1516. else
  1517. {
  1518. txProfile.TransactionId = -1;
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1521. {
  1522. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1523. }
  1524. else
  1525. {
  1526. txProfile.ChargingSchedule.Duration = -1;
  1527. }
  1528. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1529. {
  1530. 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")));
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1535. }
  1536. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1537. {
  1538. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1539. }
  1540. else
  1541. {
  1542. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. json_object_put(obj);
  1548. }
  1549. fclose(fp);
  1550. /*
  1551. if(defaultTxProfile.ChargingProfileId != -1)
  1552. {
  1553. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1554. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1555. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1556. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1557. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1558. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1559. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1560. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1561. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1562. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1563. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1564. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1565. {
  1566. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1567. {
  1568. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1569. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1570. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1571. }
  1572. }
  1573. }
  1574. else
  1575. DEBUG_INFO("TxProfile not found.\n");*/
  1576. }
  1577. /*
  1578. * Align found profile start schedule & periods
  1579. */
  1580. //DEBUG_INFO("====================================\n");
  1581. /*
  1582. // For local test usage, force modify found profile start schedule info
  1583. 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);
  1584. 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);
  1585. 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);
  1586. */
  1587. if(maxProfile.ChargingProfileId != -1)
  1588. {
  1589. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1590. {
  1591. if(maxProfile.ChargingSchedule.Duration != -1)
  1592. {
  1593. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1594. 0:
  1595. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1596. }
  1597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1598. {
  1599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1600. {
  1601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1602. 0:
  1603. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1604. }
  1605. }
  1606. }
  1607. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1608. {
  1609. if(maxProfile.ChargingSchedule.Duration != -1)
  1610. {
  1611. 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?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1616. {
  1617. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1618. {
  1619. 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?
  1620. 0:
  1621. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1622. }
  1623. }
  1624. }
  1625. else
  1626. {
  1627. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1628. {
  1629. if(maxProfile.ChargingSchedule.Duration != -1)
  1630. {
  1631. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1632. 0:
  1633. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1634. }
  1635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1636. {
  1637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1638. {
  1639. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1640. 0:
  1641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1642. }
  1643. }
  1644. }
  1645. else
  1646. {
  1647. if(maxProfile.ChargingSchedule.Duration != -1)
  1648. {
  1649. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1650. 0:
  1651. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1652. }
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1656. {
  1657. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1658. 0:
  1659. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1660. }
  1661. }
  1662. }
  1663. }
  1664. /*
  1665. DEBUG_INFO("MaxProfile after align.\n");
  1666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1672. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1673. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1678. {
  1679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1680. {
  1681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1684. }
  1685. }
  1686. DEBUG_INFO("------------------------------------\n");*/
  1687. }
  1688. if(defaultTxProfile.ChargingProfileId != -1)
  1689. {
  1690. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1691. {
  1692. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1693. {
  1694. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1695. 0:
  1696. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1697. }
  1698. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1699. {
  1700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1701. {
  1702. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1703. 0:
  1704. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1705. }
  1706. }
  1707. }
  1708. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1711. {
  1712. 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?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1719. {
  1720. 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?
  1721. 0:
  1722. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1723. }
  1724. }
  1725. }
  1726. else
  1727. {
  1728. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1729. {
  1730. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1731. {
  1732. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1733. 0:
  1734. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1735. }
  1736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1737. {
  1738. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1739. {
  1740. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1741. 0:
  1742. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1743. }
  1744. }
  1745. }
  1746. else
  1747. {
  1748. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1749. {
  1750. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1751. 0:
  1752. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1753. }
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1757. {
  1758. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1759. 0:
  1760. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1761. }
  1762. }
  1763. }
  1764. }
  1765. /*
  1766. DEBUG_INFO("defaultTxProfile after align.\n");
  1767. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1768. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1769. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1770. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1771. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1772. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1773. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1774. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1775. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1776. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1777. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1778. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1779. {
  1780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1781. {
  1782. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1783. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1784. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1785. }
  1786. }
  1787. DEBUG_INFO("------------------------------------\n");*/
  1788. }
  1789. if(txProfile.ChargingProfileId != -1)
  1790. {
  1791. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1792. {
  1793. if(txProfile.ChargingSchedule.Duration != -1)
  1794. {
  1795. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1796. 0:
  1797. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1798. }
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1802. {
  1803. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1804. 0:
  1805. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1806. }
  1807. }
  1808. }
  1809. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1810. {
  1811. if(txProfile.ChargingSchedule.Duration != -1)
  1812. {
  1813. 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?
  1814. 0:
  1815. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1818. {
  1819. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1820. {
  1821. 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?
  1822. 0:
  1823. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1824. }
  1825. }
  1826. }
  1827. else
  1828. {
  1829. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1830. {
  1831. if(txProfile.ChargingSchedule.Duration != -1)
  1832. {
  1833. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1834. 0:
  1835. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1836. }
  1837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1838. {
  1839. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1840. {
  1841. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1842. 0:
  1843. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1844. }
  1845. }
  1846. }
  1847. else
  1848. {
  1849. if(txProfile.ChargingSchedule.Duration != -1)
  1850. {
  1851. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1852. 0:
  1853. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1854. }
  1855. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1856. {
  1857. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1858. {
  1859. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1860. 0:
  1861. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1862. }
  1863. }
  1864. }
  1865. }
  1866. /*
  1867. DEBUG_INFO("txProfile after align.\n");
  1868. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1869. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1870. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1871. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1872. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1873. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1874. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1875. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1876. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1877. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1878. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1879. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1880. {
  1881. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1882. {
  1883. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1884. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1885. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1886. }
  1887. }*/
  1888. }
  1889. /*
  1890. * Merge to conposite schedule
  1891. */
  1892. //DEBUG_INFO("====================================\n");
  1893. // Find each profile period quantity
  1894. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1895. {
  1896. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1897. limitMax = idx+1;
  1898. }
  1899. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1902. limitDef = idx+1;
  1903. }
  1904. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1905. {
  1906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1907. limitTx = idx+1;
  1908. }
  1909. // TxProfile found, composite schedule based on it
  1910. if(txProfile.ChargingProfileId != -1)
  1911. {
  1912. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1913. {
  1914. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1915. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1916. {
  1917. if(maxProfile.ChargingProfileId != -1)
  1918. {
  1919. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1920. {
  1921. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1922. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1923. {
  1924. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1925. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1926. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1927. }
  1928. if(idxMaxPeriod == (limitMax-1))
  1929. {
  1930. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1931. {
  1932. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1933. {
  1934. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1935. compositePeriodIdx++;
  1936. }
  1937. else
  1938. {
  1939. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1940. }
  1941. }
  1942. }
  1943. }
  1944. }
  1945. else
  1946. {
  1947. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1948. {
  1949. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1950. compositePeriodIdx++;
  1951. }
  1952. else
  1953. {
  1954. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1955. }
  1956. }
  1957. }
  1958. if(idxTxPeriod == (limitTx-1))
  1959. {
  1960. if(defaultTxProfile.ChargingProfileId != -1)
  1961. {
  1962. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1963. {
  1964. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1965. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1966. {
  1967. if(maxProfile.ChargingProfileId != -1)
  1968. {
  1969. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1970. {
  1971. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1972. {
  1973. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1974. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1975. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1976. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1977. {
  1978. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1979. {
  1980. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1981. compositePeriodIdx++;
  1982. }
  1983. else
  1984. {
  1985. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1986. }
  1987. }
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. else
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1995. {
  1996. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1997. compositePeriodIdx++;
  1998. }
  1999. else
  2000. {
  2001. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2011. else if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2014. {
  2015. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2016. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  2017. {
  2018. if(maxProfile.ChargingProfileId != -1)
  2019. {
  2020. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2021. {
  2022. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2023. {
  2024. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2025. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2026. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2027. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2028. {
  2029. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2030. {
  2031. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2032. compositePeriodIdx++;
  2033. }
  2034. else
  2035. {
  2036. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2037. }
  2038. }
  2039. break;
  2040. }
  2041. }
  2042. }
  2043. else
  2044. {
  2045. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2046. {
  2047. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2048. compositePeriodIdx++;
  2049. }
  2050. else
  2051. {
  2052. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. // Fill other period by MaxProfile
  2059. if(maxProfile.ChargingProfileId != -1)
  2060. {
  2061. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2062. {
  2063. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2064. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2065. {
  2066. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2067. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2068. {
  2069. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2070. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2071. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2072. }
  2073. if(idxMaxPeriod == (limitMax-1))
  2074. {
  2075. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2076. {
  2077. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2078. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2079. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2080. }
  2081. if(tmpPeriod.Limit != -1)
  2082. {
  2083. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2084. {
  2085. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2086. {
  2087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2088. compositePeriodIdx++;
  2089. }
  2090. else
  2091. {
  2092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2101. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2102. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2103. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2104. {
  2105. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2106. {
  2107. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2108. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2109. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2110. }
  2111. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2112. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2113. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2114. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2115. }
  2116. if(line)
  2117. free(line);
  2118. }
  2119. //==========================================
  2120. // Init all share memory
  2121. //==========================================
  2122. int InitShareMemory()
  2123. {
  2124. int result = PASS;
  2125. int MeterSMId;
  2126. //creat ShmSysConfigAndInfo
  2127. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2128. {
  2129. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2130. result = FAIL;
  2131. }
  2132. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2133. {
  2134. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2135. result = FAIL;
  2136. }
  2137. else
  2138. {}
  2139. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2140. {
  2141. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2142. result = FAIL;
  2143. }
  2144. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2145. {
  2146. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2147. result = FAIL;
  2148. }
  2149. else
  2150. {}
  2151. //creat ShmPsuData
  2152. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2153. {
  2154. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2155. result = FAIL;
  2156. }
  2157. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2158. {
  2159. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2160. result = FAIL;
  2161. }
  2162. else
  2163. {}
  2164. //creat ShmOCPP16Data
  2165. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2166. {
  2167. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2168. result = FAIL;
  2169. }
  2170. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2171. {
  2172. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2173. result = FAIL;
  2174. }
  2175. else
  2176. {}
  2177. /****************************** For Initial Settings************************************************/
  2178. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2179. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2180. // allocate Configuration memory address
  2181. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2182. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2183. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2184. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2185. //offline MeterValue Interval
  2186. TempMeterValueInterval = 0;
  2187. return result;
  2188. }
  2189. int ProcessShareMemory()
  2190. {
  2191. if(InitShareMemory() == FAIL)
  2192. {
  2193. DEBUG_ERROR("InitShareMemory NG\n");
  2194. if(ShmStatusCodeData!=NULL)
  2195. {
  2196. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2197. }
  2198. sleep(5);
  2199. return FAIL;
  2200. }
  2201. return PASS;
  2202. }
  2203. //---------------------common routine---------------------------//
  2204. int isOFFline(void)
  2205. {
  2206. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2207. {
  2208. if(TempMeterValueInterval >= 2 )
  2209. {
  2210. TempMeterValueInterval = 0;
  2211. return TRUE;
  2212. }
  2213. else
  2214. {
  2215. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2216. return FALSE;
  2217. }
  2218. }
  2219. else
  2220. {
  2221. return FALSE;
  2222. }
  2223. }
  2224. //---------------------------------------------
  2225. // new:
  2226. // enum SYSTEM_STATUS
  2227. // {
  2228. // SYS_MODE_BOOTING = 0,
  2229. // SYS_MODE_IDLE = 1,
  2230. // SYS_MODE_AUTHORIZING = 2,
  2231. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2232. // SYS_MODE_REASSIGN = 4,
  2233. // SYS_MODE_PREPARING = 5,
  2234. // SYS_MODE_PREPARE_FOR_EV = 6,
  2235. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2236. // SYS_MODE_CHARGING = 8,
  2237. // SYS_MODE_TERMINATING = 9,
  2238. // SYS_MODE_COMPLETE = 10,
  2239. // SYS_MODE_ALARM = 11,
  2240. // SYS_MODE_FAULT = 12,
  2241. // SYS_MODE_RESERVATION = 13,
  2242. // SYS_MODE_BOOKING = 14,
  2243. // SYS_MODE_MAINTAIN = 15,
  2244. // SYS_MODE_DEBUG = 16,
  2245. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2246. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2247. // SYS_MODE_UPDATE = 19
  2248. // };
  2249. //
  2250. //
  2251. //-----------------------------------------
  2252. void CheckSystemValue(void)
  2253. {
  2254. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2255. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2256. char filenmae[100]={0};
  2257. char str[100]={0};
  2258. //===============================
  2259. // send Heartbeat
  2260. //===============================
  2261. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2262. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2263. {
  2264. clientTime.Heartbeat=time((time_t*)NULL);
  2265. if(server_sign == TRUE)
  2266. {
  2267. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2268. }
  2269. else
  2270. {
  2271. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2272. }
  2273. }
  2274. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2275. {
  2276. //parameter for test
  2277. sendHeartbeatRequest(0);
  2278. //==============================================
  2279. // Reset Waiting Time
  2280. //==============================================
  2281. clientTime.Heartbeat=time((time_t*)NULL);
  2282. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2283. }
  2284. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2285. {
  2286. //===============================
  2287. // CSU Trigger Reset Conf
  2288. //===============================
  2289. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2290. {
  2291. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2292. }
  2293. //===============================
  2294. // CSU Trigger Authorize Request
  2295. //===============================
  2296. if(isWebsocketSendable && isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2297. {
  2298. sendAuthorizeRequest(0);
  2299. authorizeRetryTimes = authorizeRetryTimes + 1;
  2300. if(authorizeRetryTimes < 3)
  2301. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2302. }
  2303. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2304. {
  2305. authorizeRetryTimes = 0;
  2306. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2307. server_sign = FALSE;
  2308. }
  2309. 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))
  2310. {
  2311. sendAuthorizeRequest(0);
  2312. }
  2313. //===============================
  2314. // CSU Trigger Smart Charging Profilw
  2315. //===============================
  2316. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2317. {
  2318. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2319. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2320. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2321. }
  2322. //==============================================
  2323. // Charger start transaction
  2324. //==============================================
  2325. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2326. {
  2327. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2328. sendStartTransactionRequest(gun_index);
  2329. clientTime.StartTransaction = time((time_t*)NULL);
  2330. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2331. }
  2332. //==============================================
  2333. // Charger stop transaction
  2334. //==============================================
  2335. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2336. {
  2337. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2338. sendStopTransactionRequest(gun_index);
  2339. clientTime.StopTransaction = time((time_t*)NULL);
  2340. }
  2341. //==============================================
  2342. // Charger status report
  2343. //==============================================
  2344. //--- Check Mode Change ---//
  2345. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2346. if(gunType[gun_index] == 'J')
  2347. {
  2348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2349. {
  2350. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2351. {
  2352. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2353. {
  2354. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2355. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2356. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2357. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2358. statusModeChage[gun_index] = TRUE;
  2359. }
  2360. #if 1 // for TempStopTransaction
  2361. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2362. {
  2363. checkTempStopTransaction(gun_index);
  2364. }
  2365. #endif
  2366. }
  2367. }
  2368. }
  2369. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2370. {
  2371. for (int index = 0; index < CCS_QUANTITY; index++)
  2372. {
  2373. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2374. {
  2375. if((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]*/ )
  2376. {
  2377. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2378. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2379. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2381. statusModeChage[gun_index] = TRUE;
  2382. }
  2383. #if 1 // for TempStopTransaction
  2384. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2385. {
  2386. checkTempStopTransaction(gun_index);
  2387. }
  2388. #endif
  2389. }
  2390. }
  2391. }
  2392. else if(gunType[gun_index] == 'G')
  2393. {
  2394. for (int index = 0; index < GB_QUANTITY; index++)
  2395. {
  2396. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2397. {
  2398. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2399. {
  2400. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2401. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2402. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2403. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2404. statusModeChage[gun_index] = TRUE;
  2405. }
  2406. #if 1 // for TempStopTransaction
  2407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2408. {
  2409. checkTempStopTransaction(gun_index);
  2410. }
  2411. #endif
  2412. }
  2413. }
  2414. }
  2415. else
  2416. {
  2417. for (int index = 0; index < AC_QUANTITY; index++)
  2418. {
  2419. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2420. {
  2421. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2422. {
  2423. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2424. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2425. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2426. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2427. statusModeChage[gun_index] = TRUE;
  2428. }
  2429. #if 1 // for TempStopTransaction
  2430. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2431. {
  2432. checkTempStopTransaction(gun_index);
  2433. }
  2434. #endif
  2435. }
  2436. }// END
  2437. }
  2438. if(isWebsocketSendable &&
  2439. (((server_sign == TRUE) && (SystemInitial > 0)) ||
  2440. ((server_sign == TRUE) && ((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]) > 30))))) )
  2441. {
  2442. if(SystemInitial > 0)
  2443. SystemInitial = SystemInitial -1;
  2444. sendStatusNotificationRequest(gun_index);
  2445. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2446. statusModeChage[gun_index] = FALSE;
  2447. }
  2448. //==============================================
  2449. // Meter report
  2450. //==============================================
  2451. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
  2452. (((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)))
  2453. {
  2454. //check Transaction active
  2455. if(gunType[gun_index] == 'J')
  2456. {
  2457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2458. {
  2459. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2460. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2461. {
  2462. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2463. {
  2464. reqSampleMeter[gun_index] = 1;
  2465. }
  2466. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2467. {
  2468. reqClockAlignMeter[gun_index] = 1;
  2469. }
  2470. }
  2471. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2472. {
  2473. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2474. if((access(filenmae,F_OK))!=-1)
  2475. {
  2476. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2477. sprintf(str,"rm -f %s",filenmae);
  2478. system(str);
  2479. }
  2480. }
  2481. }// End for CHAdeMO
  2482. }
  2483. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2484. {
  2485. for (int index = 0; index < CCS_QUANTITY; index++)
  2486. {
  2487. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2489. {
  2490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2491. {
  2492. reqSampleMeter[gun_index] = 1;
  2493. }
  2494. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2495. {
  2496. reqClockAlignMeter[gun_index] = 1;
  2497. }
  2498. }
  2499. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2500. {
  2501. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2502. if((access(filenmae,F_OK))!=-1)
  2503. {
  2504. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2505. sprintf(str,"rm -f %s",filenmae);
  2506. system(str);
  2507. }
  2508. }
  2509. } // End for CCS
  2510. }
  2511. else if(gunType[gun_index] == 'G')
  2512. {
  2513. for (int index = 0; index < GB_QUANTITY; index++)
  2514. {
  2515. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2516. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2517. {
  2518. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2519. {
  2520. reqSampleMeter[gun_index] = 1;
  2521. }
  2522. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2523. {
  2524. reqClockAlignMeter[gun_index] = 1;
  2525. }
  2526. }
  2527. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2528. {
  2529. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2530. if((access(filenmae,F_OK))!=-1)
  2531. {
  2532. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2533. sprintf(str,"rm -f %s",filenmae);
  2534. system(str);
  2535. }
  2536. }
  2537. }// End for GB
  2538. }
  2539. else
  2540. {
  2541. for (int index = 0; index < AC_QUANTITY; index++)
  2542. {
  2543. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2544. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2545. {
  2546. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2547. {
  2548. reqSampleMeter[gun_index] = 1;
  2549. }
  2550. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2551. {
  2552. reqClockAlignMeter[gun_index] = 1;
  2553. }
  2554. }
  2555. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2556. {
  2557. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2558. if((access(filenmae,F_OK))!=-1)
  2559. {
  2560. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2561. sprintf(str,"rm -f %s",filenmae);
  2562. system(str);
  2563. }
  2564. }
  2565. }//End for AC
  2566. }
  2567. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2568. if(reqSampleMeter[gun_index] == 1)
  2569. {
  2570. sendMeterValuesRequest(gun_index);
  2571. storeTempStopTransaction(gun_index);
  2572. }
  2573. else if(reqClockAlignMeter[gun_index] == 1)
  2574. {
  2575. sendMeterValuesRequest(gun_index);
  2576. }
  2577. sleep(1);
  2578. }
  2579. //==============================================
  2580. // Check Connector reserved
  2581. //==============================================
  2582. //===============================
  2583. // Check if Reserve is expired
  2584. //===============================
  2585. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2586. {
  2587. double diff_t;
  2588. struct tm tp;
  2589. // current time
  2590. time_t t = time(NULL);
  2591. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2592. tp.tm_isdst = -1;
  2593. time_t utc = mktime(&tp);
  2594. diff_t = difftime(utc, t);
  2595. if(diff_t <= 0)
  2596. {
  2597. DEBUG_INFO("reserve expired.\n");
  2598. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2599. }
  2600. }//END OF Check if Reserve is expired
  2601. //==========================================
  2602. // csu trigger FirmwareStatusNotificationReq
  2603. //==========================================
  2604. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2605. {
  2606. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2607. }
  2608. //==========================================
  2609. // csu trigger CancelReservationConf
  2610. //==========================================
  2611. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2612. {
  2613. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2614. }
  2615. //==========================================
  2616. // csu trigger ChangeAvailabilityConf
  2617. //==========================================
  2618. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2619. {
  2620. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2621. }
  2622. //==========================================
  2623. // csu trigger UnlockConnectorConf
  2624. //==========================================
  2625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2626. {
  2627. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2628. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2629. }
  2630. //==========================================
  2631. // csu trigger ReserveNowConf
  2632. //==========================================
  2633. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2634. {
  2635. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2636. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2637. }
  2638. //==========================================
  2639. // csu trigger DataTransferReq
  2640. //==========================================
  2641. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2642. {
  2643. sendDataTransferRequest(gun_index);
  2644. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2645. }
  2646. }
  2647. }
  2648. //==========================================
  2649. // send request routine
  2650. //==========================================
  2651. int sendAuthorizeRequest(int gun_index)
  2652. {
  2653. mtrace();
  2654. int result = FAIL;
  2655. char message[100]={0};
  2656. char guid[37];
  2657. char tempdata[65]={0};
  2658. DEBUG_INFO("sendAuthorizeRequest...\n");
  2659. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2660. //Local Authorize
  2661. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2662. {
  2663. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2664. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2665. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2666. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2667. result = PASS;
  2668. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2669. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2670. authorizeRetryTimes = 0;
  2671. return result;
  2672. }
  2673. 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))||
  2674. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2675. {
  2676. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2677. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2678. {
  2679. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2680. {
  2681. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2682. }
  2683. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2684. {
  2685. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2686. }
  2687. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2688. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2689. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2690. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2691. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2692. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2693. authorizeRetryTimes = 0;
  2694. return result;
  2695. }
  2696. else
  2697. {
  2698. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2699. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2700. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2701. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2702. result = PASS;
  2703. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2704. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2705. authorizeRetryTimes = 0;
  2706. return result;
  2707. }
  2708. }
  2709. //initailize struct Authorize
  2710. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2711. //get data from shared memory
  2712. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2713. random_uuid(guid);
  2714. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2715. LWS_Send(message);
  2716. sprintf(tempdata, "Authorize,%d", gun_index);
  2717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2718. {
  2719. result = PASS;
  2720. DEBUG_INFO("Authorize mapItem pass\n");
  2721. }
  2722. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2723. return result;
  2724. }
  2725. int sendBootNotificationRequest(void)
  2726. {
  2727. mtrace();
  2728. int result = FAIL;
  2729. char message[500]={0}, payload[700]={0};
  2730. char guid[37]={0};
  2731. char tempdata[65]={0};
  2732. int IsGunCharging = FALSE;
  2733. //check Transaction active
  2734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2735. {
  2736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2737. {
  2738. IsGunCharging = TRUE;
  2739. }
  2740. }
  2741. for (int index = 0; index < CCS_QUANTITY; index++)
  2742. {
  2743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2744. {
  2745. IsGunCharging = TRUE;
  2746. }
  2747. }
  2748. for (int index = 0; index < GB_QUANTITY; index++)
  2749. {
  2750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2751. {
  2752. IsGunCharging = TRUE;
  2753. }
  2754. }
  2755. for (int index = 0; index < AC_QUANTITY; index++)
  2756. {
  2757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2758. {
  2759. IsGunCharging = TRUE;
  2760. }
  2761. }
  2762. if(IsGunCharging == TRUE)
  2763. {
  2764. server_sign = TRUE;
  2765. return result;
  2766. }
  2767. // Fill BootNotification fields
  2768. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2769. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2770. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2771. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2772. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2773. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2774. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2775. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2776. ShmOCPP16Data->ChargeBoxId
  2777. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2778. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2779. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2780. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2781. ,ShmOCPP16Data->BootNotification.CpIccid
  2782. ,ShmOCPP16Data->BootNotification.CpImsi);
  2783. random_uuid(guid);
  2784. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2785. LWS_Send(message);
  2786. sprintf(tempdata, "BootNotification,0");
  2787. 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*/)
  2788. {
  2789. result = PASS;
  2790. }
  2791. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2792. strcpy(queuedata,message);
  2793. return result;
  2794. }
  2795. int sendDataTransferRequest(int gun_index)
  2796. {
  2797. mtrace();
  2798. char message[1000]={0};
  2799. char guid[37]={0};
  2800. char tempdata[65]={0};
  2801. int result = FAIL;
  2802. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2803. random_uuid(guid);
  2804. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2805. MESSAGE_TYPE_CALL,
  2806. guid,
  2807. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2808. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2809. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2810. LWS_Send(message);
  2811. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2812. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2813. {
  2814. result = PASS;
  2815. DEBUG_INFO("DataTransfer mapItem pass\n");
  2816. }
  2817. return result;
  2818. }
  2819. int sendDiagnosticsStatusNotificationRequest(char *status)
  2820. {
  2821. mtrace();
  2822. int result = FAIL;
  2823. char message[110]={0};
  2824. char guid[37]={0};
  2825. char tempdata[65]={0};
  2826. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2827. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2828. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2829. random_uuid(guid);
  2830. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2831. LWS_Send(message);
  2832. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2833. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2834. {
  2835. result = PASS;
  2836. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2837. }
  2838. //#ifdef SystemLogMessage
  2839. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2840. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2841. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2842. //#endif
  2843. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2844. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2845. //record status
  2846. if(strcmp(status,"Idle")==0)
  2847. {
  2848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2849. }
  2850. else if(strcmp(status,"Uploaded")==0)
  2851. {
  2852. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2853. }
  2854. else if(strcmp(status,"UploadFailed")==0)
  2855. {
  2856. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2857. }
  2858. else if(strcmp(status,"Uploading")==0)
  2859. {
  2860. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2861. }
  2862. return result;
  2863. }
  2864. int sendFirmwareStatusNotificationRequest(char *status)
  2865. {
  2866. mtrace();
  2867. int result = FAIL;
  2868. char message[110]={0};
  2869. char guid[37]={0};
  2870. char tempdata[65]={0};
  2871. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2872. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2873. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2874. random_uuid(guid);
  2875. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2876. LWS_Send(message);
  2877. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2878. 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*/)
  2879. {
  2880. result = PASS;
  2881. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2882. }
  2883. //#ifdef SystemLogMessage
  2884. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2885. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2886. //#endif
  2887. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2888. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2889. //record status
  2890. if(strcmp(status,"Downloaded")==0)
  2891. {
  2892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2893. }
  2894. else if(strcmp(status,"DownloadFailed")==0)
  2895. {
  2896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2897. }
  2898. else if(strcmp(status,"Downloading")==0)
  2899. {
  2900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2901. }
  2902. else if(strcmp(status,"Idle")==0)
  2903. {
  2904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2905. }
  2906. else if(strcmp(status,"InstallationFailed")==0)
  2907. {
  2908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2909. }
  2910. else if(strcmp(status,"Installing")==0)
  2911. {
  2912. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2913. }
  2914. else if(strcmp(status,"Installed")==0)
  2915. {
  2916. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2917. }
  2918. return result;
  2919. }
  2920. int sendHeartbeatRequest(int gun_index)
  2921. {
  2922. mtrace();
  2923. int result = FAIL;
  2924. char message[80]={0};
  2925. char guid[37]={0};
  2926. char tempdata[65]={0};
  2927. random_uuid(guid);
  2928. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2929. , MESSAGE_TYPE_CALL
  2930. , guid );
  2931. LWS_Send(message);
  2932. sprintf(tempdata, "Heartbeat,%d", 0);
  2933. 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*/)
  2934. {
  2935. result = PASS;
  2936. }
  2937. return result;
  2938. }
  2939. int sendStartTransactionRequest(int gun_index)
  2940. {
  2941. mtrace();
  2942. int result = FAIL;
  2943. char message[250]={0};
  2944. char guid[37]={0};
  2945. struct timeval tmnow;
  2946. struct tm *tm;
  2947. char buf[28];//, usec_buf[6];
  2948. char tempdata[65]={0};
  2949. int tempIndex = 0;
  2950. DEBUG_INFO("sendStartTransactionRequest...\n");
  2951. gettimeofday(&tmnow, NULL);
  2952. time_t t;
  2953. t = time(NULL);
  2954. /*UTC time and date*/
  2955. tm = gmtime(&t);
  2956. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2957. #if 0 // remove temporally
  2958. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2959. strcat(buf,".");
  2960. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2961. strcat(buf,usec_buf);
  2962. #endif
  2963. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2964. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2965. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2966. // clear StartTransaction Response
  2967. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2968. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2969. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2970. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2971. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2972. if(gunType[gun_index] == 'J')
  2973. {
  2974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2975. {
  2976. tempIndex = ((gun_index==2) ? 1: 0);
  2977. }
  2978. else
  2979. {
  2980. tempIndex = gun_index;
  2981. }
  2982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2983. {
  2984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2985. {
  2986. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2987. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2988. }
  2989. }
  2990. }
  2991. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2992. {
  2993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2994. {
  2995. tempIndex = ((gun_index==2) ? 1: 0);
  2996. }
  2997. else
  2998. {
  2999. tempIndex = gun_index;
  3000. }
  3001. for (int index = 0; index < CCS_QUANTITY; index++)
  3002. {
  3003. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3004. {
  3005. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  3006. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3007. }
  3008. }
  3009. }
  3010. else if(gunType[gun_index] == 'G')
  3011. {
  3012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3013. {
  3014. tempIndex = ((gun_index==2) ? 1: 0);
  3015. }
  3016. else
  3017. {
  3018. tempIndex = gun_index;
  3019. }
  3020. for (int index = 0; index < GB_QUANTITY; index++)
  3021. {
  3022. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3023. {
  3024. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3025. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3026. }
  3027. }
  3028. }
  3029. else
  3030. {
  3031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3032. {
  3033. tempIndex = 2;
  3034. }
  3035. else
  3036. {
  3037. tempIndex = gun_index;
  3038. }
  3039. for (int index = 0; index < AC_QUANTITY; index++)
  3040. {
  3041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3042. {
  3043. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3044. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3045. }
  3046. }
  3047. }
  3048. random_uuid(guid);
  3049. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3050. {
  3051. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3052. , gun_index +1
  3053. , MESSAGE_TYPE_CALL
  3054. , guid
  3055. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3056. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3057. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3058. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3059. }
  3060. else
  3061. {
  3062. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3063. , gun_index +1
  3064. , MESSAGE_TYPE_CALL
  3065. , guid
  3066. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3067. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3068. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3069. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3070. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3071. }
  3072. #if 1
  3073. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3074. 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*/)
  3075. {
  3076. result = PASS;
  3077. }
  3078. #endif
  3079. strcpy(queuedata, message);
  3080. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3081. /*
  3082. if(GetTransactionQueueNum() == 1)
  3083. {
  3084. LWS_Send(message + 2);
  3085. }*/
  3086. return result;
  3087. }
  3088. int sendStatusNotificationRequest(int gun_index)
  3089. {
  3090. mtrace();
  3091. int result = FAIL;
  3092. char message[600]={0};
  3093. char guid[37];
  3094. int currentStatus = 0;
  3095. struct timeval tmnow;
  3096. struct tm *tm;
  3097. char buf[28];//, usec_buf[6];
  3098. char tempdata[65]={0};
  3099. int tempIndex = 0;
  3100. gettimeofday(&tmnow, NULL);
  3101. time_t t;
  3102. t = time(NULL);
  3103. /*UTC time and date*/
  3104. tm = gmtime(&t);
  3105. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3106. #if 0 // remove temporally
  3107. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3108. strcat(buf,".");
  3109. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3110. strcat(buf,usec_buf);
  3111. #endif
  3112. printf("%s",buf);
  3113. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3114. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3115. // it's option
  3116. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3117. /*
  3118. enum _SYSTEM_STATUS
  3119. {
  3120. S_BOOTING = 0,
  3121. S_IDLE, = 1
  3122. S_AUTHORIZING, =2
  3123. S_REASSIGN_CHECK, =3
  3124. S_REASSIGN, =4
  3125. S_PRECHARGE, =5
  3126. S_PREPARING_FOR_EV, =6
  3127. S_PREPARING_FOR_EVSE, =7
  3128. S_CHARGING, =8
  3129. S_TERMINATING, =9
  3130. S_COMPLETE, =10
  3131. S_ALARM, =11
  3132. S_FAULT =12
  3133. }
  3134. */
  3135. //check Transaction active
  3136. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3137. if(gunType[gun_index] == 'J')
  3138. {
  3139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3140. {
  3141. tempIndex = ((gun_index==2) ? 1: 0);
  3142. }
  3143. else
  3144. {
  3145. tempIndex = gun_index;
  3146. }
  3147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3148. {
  3149. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3150. {
  3151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3152. {
  3153. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3154. {
  3155. currentStatus = 1; //OCPP Status: Preparing
  3156. }
  3157. else
  3158. {
  3159. currentStatus = 0; //OCPP Status: Available
  3160. }
  3161. }
  3162. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3163. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3164. ) //S_PRECHARGE
  3165. {
  3166. currentStatus = 1; //OCPP Status: Preparing
  3167. }
  3168. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3169. {
  3170. currentStatus = 2; //OCPP Status: Charging
  3171. }
  3172. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3173. {
  3174. currentStatus = 5; //OCPP Status: Finishing
  3175. }
  3176. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3177. {
  3178. currentStatus = 4; //OCPP Status: SuspendedEV
  3179. }
  3180. 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
  3181. {
  3182. currentStatus = 7; //OCPP Status: Unavailable
  3183. }
  3184. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3185. {
  3186. currentStatus = 8; //OCPP Status: Faulted
  3187. }
  3188. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3189. {
  3190. currentStatus = 6; //OCPP Status: Reserved
  3191. }
  3192. } //end of the same index
  3193. }//end of for CHAdeMO_QUANTITY
  3194. }
  3195. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3196. {
  3197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3198. {
  3199. tempIndex = ((gun_index==2) ? 1: 0);
  3200. }
  3201. else
  3202. {
  3203. tempIndex = gun_index;
  3204. }
  3205. for (int index = 0; index < CCS_QUANTITY; index++)
  3206. {
  3207. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3208. {
  3209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3210. {
  3211. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3212. {
  3213. currentStatus = 1; //OCPP Status: Preparing
  3214. }
  3215. else
  3216. {
  3217. currentStatus = 0; //OCPP Status: Available
  3218. }
  3219. }
  3220. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3221. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3222. ) //S_PRECHARGE
  3223. {
  3224. currentStatus = 1; //OCPP Status: Preparing
  3225. }
  3226. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3227. {
  3228. currentStatus = 2; //OCPP Status: Charging
  3229. }
  3230. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3231. {
  3232. currentStatus = 5; //OCPP Status: Finishing
  3233. }
  3234. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3235. {
  3236. currentStatus = 4; //OCPP Status: SuspendedEV
  3237. }
  3238. 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
  3239. {
  3240. currentStatus = 7; //OCPP Status : Unavailable
  3241. }
  3242. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3243. {
  3244. currentStatus = 8; //OCPP Status: Faulted
  3245. }
  3246. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3247. {
  3248. currentStatus = 6; //OCPP Status: Reserved
  3249. }
  3250. } //end of the same index
  3251. } // end of for CCS_QUANTITY
  3252. }
  3253. else if(gunType[gun_index] == 'G')
  3254. {
  3255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3256. {
  3257. tempIndex = ((gun_index==2) ? 1: 0);
  3258. }
  3259. else
  3260. {
  3261. tempIndex = gun_index;
  3262. }
  3263. for (int index = 0; index < GB_QUANTITY; index++)
  3264. {
  3265. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3266. {
  3267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3268. {
  3269. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3270. {
  3271. currentStatus = 1; //OCPP Status: Preparing
  3272. }
  3273. else
  3274. {
  3275. currentStatus = 0; //OCPP Status: Available
  3276. }
  3277. }
  3278. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3279. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3280. ) //S_PRECHARGE
  3281. {
  3282. currentStatus = 1; //OCPP Status: Preparing
  3283. }
  3284. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3285. {
  3286. currentStatus = 2; //OCPP Status: Charging
  3287. }
  3288. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3289. {
  3290. currentStatus = 5; //OCPP Status: Finishing
  3291. }
  3292. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3293. {
  3294. currentStatus = 4; //OCPP Status: SuspendedEV
  3295. }
  3296. 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
  3297. {
  3298. currentStatus = 7; //OCPP Status: Unavailable
  3299. }
  3300. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3301. {
  3302. currentStatus = 8; //OCPP Status: Faulted
  3303. }
  3304. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3305. {
  3306. currentStatus = 6; //OCPP Status: Reserved
  3307. }
  3308. } //end of the same index
  3309. } // end of for GB_QUANTITY
  3310. }
  3311. else
  3312. {
  3313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3314. {
  3315. tempIndex = 2;
  3316. }
  3317. else
  3318. {
  3319. tempIndex = gun_index;
  3320. }
  3321. for (int index = 0; index < AC_QUANTITY; index++)
  3322. {
  3323. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3324. {
  3325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3326. {
  3327. 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))
  3328. {
  3329. currentStatus = 1; //OCPP Status: Preparing
  3330. }
  3331. else
  3332. {
  3333. currentStatus = 0; //OCPP Status: Available
  3334. }
  3335. }
  3336. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3337. {
  3338. currentStatus = 1; //OCPP Status: Preparing
  3339. }
  3340. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3341. {
  3342. currentStatus = 2; //OCPP Status: Charging
  3343. }
  3344. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3345. {
  3346. currentStatus = 5; //OCPP Status: Finishing
  3347. }
  3348. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3349. {
  3350. currentStatus = 4; //OCPP Status: SuspendedEV
  3351. }
  3352. 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
  3353. {
  3354. currentStatus = 7; //OCPP Status: Unavailable
  3355. }
  3356. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3357. {
  3358. currentStatus = 8; //OCPP Status: Faulted
  3359. }
  3360. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3361. {
  3362. currentStatus = 6; //OCPP Status: Reserved
  3363. }
  3364. }//end of the same index
  3365. }//end of for AC_QUANTITY
  3366. }
  3367. //it's option
  3368. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3369. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3370. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3371. random_uuid(guid);
  3372. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3373. , MESSAGE_TYPE_CALL
  3374. , guid
  3375. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3376. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3377. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3378. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3379. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3380. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3381. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3382. LWS_Send(message);
  3383. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3384. 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*/)
  3385. {
  3386. //DEBUG_ERROR("statusNotification mapitem pass");
  3387. result = PASS;
  3388. }
  3389. return result;
  3390. }
  3391. int sendStopTransactionRequest(int gun_index)
  3392. {
  3393. mtrace();
  3394. int result = FAIL;
  3395. //char message[1500]={0};
  3396. char guid[37]={0};
  3397. char tempdata[65]={0};
  3398. int tempIndex = 0;
  3399. //int idx_sample=0;
  3400. DEBUG_ERROR("sendStopTransactionRequest \n");
  3401. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3402. //ENERGY_ACTIVE_IMPORT_REGISTER
  3403. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3404. if(gunType[gun_index] == 'J')
  3405. {
  3406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3407. {
  3408. tempIndex = ((gun_index==2) ? 1: 0);
  3409. }
  3410. else
  3411. {
  3412. tempIndex = gun_index;
  3413. }
  3414. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3415. {
  3416. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3417. {
  3418. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3419. }
  3420. }// END OF CHAdeMO_QUANTITY
  3421. }
  3422. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3425. {
  3426. tempIndex = ((gun_index==2) ? 1: 0);
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < CCS_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3435. {
  3436. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3437. }
  3438. }// END OF CCS_QUANTITY
  3439. }
  3440. else if(gunType[gun_index] == 'G')
  3441. {
  3442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3443. {
  3444. tempIndex = ((gun_index==2) ? 1: 0);
  3445. }
  3446. else
  3447. {
  3448. tempIndex = gun_index;
  3449. }
  3450. for (int index = 0; index < GB_QUANTITY; index++)
  3451. {
  3452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3453. {
  3454. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3455. }
  3456. }// END OF GB_QUANTITY
  3457. }
  3458. else
  3459. {
  3460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3461. {
  3462. tempIndex = 2;
  3463. }
  3464. else
  3465. {
  3466. tempIndex = gun_index;
  3467. }
  3468. for (int index = 0; index < AC_QUANTITY; index++)
  3469. {
  3470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3471. {
  3472. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3473. }
  3474. }// END OF AC_QUANTITY
  3475. }
  3476. //Stop Transaction Time
  3477. struct timeval tmnow;
  3478. struct tm *tm;
  3479. char buf[28];//, usec_buf[6];
  3480. gettimeofday(&tmnow, NULL);
  3481. time_t t;
  3482. t = time(NULL);
  3483. /*UTC time and date*/
  3484. tm = gmtime(&t);
  3485. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3487. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3488. random_uuid(guid);
  3489. /***********************************transactionData******************************************************/
  3490. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3492. //=================================
  3493. // Transaction_Begin
  3494. //=================================
  3495. // Energy.Active.Export.Interval
  3496. //idx_sample=0;
  3497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3500. 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*/]);
  3501. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3502. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3503. {
  3504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3505. }
  3506. else
  3507. {
  3508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3509. }
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3512. //=================================
  3513. // Transaction_End
  3514. //=================================
  3515. //Current.Export
  3516. //idx_sample=1;
  3517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3518. if(gunType[gun_index] == 'J')
  3519. {
  3520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3521. {
  3522. tempIndex = ((gun_index==2) ? 1: 0);
  3523. }
  3524. else
  3525. {
  3526. tempIndex = gun_index;
  3527. }
  3528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3529. {
  3530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3531. {
  3532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3533. }
  3534. }// End of for CHAdeMO_QUANTITY
  3535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3536. }
  3537. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3538. {
  3539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3540. {
  3541. tempIndex = ((gun_index==2) ? 1: 0);
  3542. }
  3543. else
  3544. {
  3545. tempIndex = gun_index;
  3546. }
  3547. for (int index = 0; index < CCS_QUANTITY; index++)
  3548. {
  3549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3550. {
  3551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3552. }
  3553. }// End of for CCS_QUANTITY
  3554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3555. }
  3556. else if(gunType[gun_index] == 'G')
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3559. {
  3560. tempIndex = ((gun_index==2) ? 1: 0);
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < GB_QUANTITY; index++)
  3567. {
  3568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3569. {
  3570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3571. }
  3572. }// End of for GB_QUANTITY
  3573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3574. }
  3575. else
  3576. {
  3577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3578. {
  3579. tempIndex = 2;
  3580. }
  3581. else
  3582. {
  3583. tempIndex = gun_index;
  3584. }
  3585. for (int index = 0; index < AC_QUANTITY; index++)
  3586. {
  3587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3588. {
  3589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3590. }
  3591. }// End of for AC_QUANTITY
  3592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3593. }
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3597. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3600. //Energy.Active.Export.Interval
  3601. //idx_sample=2;
  3602. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3603. if(gunType[gun_index] == 'J')
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3606. {
  3607. tempIndex = ((gun_index==2) ? 1: 0);
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3616. {
  3617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3618. }
  3619. }// END OF CHAdeMO_QUANTITY
  3620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3621. }
  3622. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3623. {
  3624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3625. {
  3626. tempIndex = ((gun_index==2) ? 1: 0);
  3627. }
  3628. else
  3629. {
  3630. tempIndex = gun_index;
  3631. }
  3632. for (int index = 0; index < CCS_QUANTITY; index++)
  3633. {
  3634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3635. {
  3636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3637. }
  3638. }// END OF CCS_QUANTITY
  3639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3640. }
  3641. else if(gunType[gun_index] == 'G')
  3642. {
  3643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3644. {
  3645. tempIndex = ((gun_index==2) ? 1: 0);
  3646. }
  3647. else
  3648. {
  3649. tempIndex = gun_index;
  3650. }
  3651. for (int index = 0; index < GB_QUANTITY; index++)
  3652. {
  3653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3654. {
  3655. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3656. }
  3657. }// END OF GB_QUANTITY
  3658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3659. }
  3660. else
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3663. {
  3664. tempIndex = 2;
  3665. }
  3666. else
  3667. {
  3668. tempIndex = gun_index;
  3669. }
  3670. for (int index = 0; index < AC_QUANTITY; index++)
  3671. {
  3672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3673. {
  3674. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3675. }
  3676. }// END OF AC_QUANTITY
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3678. }
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3682. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3685. //Power.Active.Export
  3686. //idx_sample=3;
  3687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3688. if(gunType[gun_index] == 'J')
  3689. {
  3690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3691. {
  3692. tempIndex = ((gun_index==2) ? 1: 0);
  3693. }
  3694. else
  3695. {
  3696. tempIndex = gun_index;
  3697. }
  3698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3699. {
  3700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3701. {
  3702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3703. }
  3704. } // End for CHAdeMO_QUANTITY
  3705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3706. }
  3707. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3708. {
  3709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3710. {
  3711. tempIndex = ((gun_index==2) ? 1: 0);
  3712. }
  3713. else
  3714. {
  3715. tempIndex = gun_index;
  3716. }
  3717. for (int index = 0; index < CCS_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3722. }
  3723. } // END for CCS_QUANTITY
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3725. }
  3726. else if(gunType[gun_index] == 'G')
  3727. {
  3728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3729. {
  3730. tempIndex = ((gun_index==2) ? 1: 0);
  3731. }
  3732. else
  3733. {
  3734. tempIndex = gun_index;
  3735. }
  3736. for (int index = 0; index < GB_QUANTITY; index++)
  3737. {
  3738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3739. {
  3740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3741. }
  3742. }// END for GB_QUANTITY
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3744. }
  3745. else
  3746. {
  3747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3748. {
  3749. tempIndex = 2;
  3750. }
  3751. else
  3752. {
  3753. tempIndex = gun_index;
  3754. }
  3755. for (int index = 0; index < AC_QUANTITY; index++)
  3756. {
  3757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3758. {
  3759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3760. }
  3761. } // END for AC_QUANTITY
  3762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3763. }
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3767. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3770. //Voltage
  3771. //idx_sample=4;
  3772. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3773. if(gunType[gun_index] == 'J')
  3774. {
  3775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3776. {
  3777. tempIndex = ((gun_index==2) ? 1: 0);
  3778. }
  3779. else
  3780. {
  3781. tempIndex = gun_index;
  3782. }
  3783. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3784. {
  3785. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3786. {
  3787. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3788. }
  3789. } // END OF FOR CHAdeMO_QUANTITY
  3790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3791. }
  3792. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3793. {
  3794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3795. {
  3796. tempIndex = ((gun_index==2) ? 1: 0);
  3797. }
  3798. else
  3799. {
  3800. tempIndex = gun_index;
  3801. }
  3802. for (int index = 0; index < CCS_QUANTITY; index++)
  3803. {
  3804. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3805. {
  3806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3807. }
  3808. } // END OF FOR CCS_QUANTITY
  3809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3810. }
  3811. else if(gunType[gun_index] == 'G')
  3812. {
  3813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3814. {
  3815. tempIndex = ((gun_index==2) ? 1: 0);
  3816. }
  3817. else
  3818. {
  3819. tempIndex = gun_index;
  3820. }
  3821. for (int index = 0; index < GB_QUANTITY; index++)
  3822. {
  3823. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3824. {
  3825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3826. }
  3827. } // END OF FOR GB_QUANTITY
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3829. }
  3830. else
  3831. {
  3832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3833. {
  3834. tempIndex = 2;
  3835. }
  3836. else
  3837. {
  3838. tempIndex = gun_index;
  3839. }
  3840. for (int index = 0; index < AC_QUANTITY; index++)
  3841. {
  3842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3843. {
  3844. 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
  3845. }
  3846. } // END OF FOR AC_QUANTITY
  3847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3848. }
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3852. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3855. //SoC
  3856. //idx_sample=5;
  3857. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3858. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3859. {
  3860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3861. {
  3862. tempIndex = ((gun_index==2) ? 1: 0);
  3863. }
  3864. else
  3865. {
  3866. tempIndex = gun_index;
  3867. }
  3868. if(gunType[gun_index] == 'J')
  3869. {
  3870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3871. {
  3872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3873. {
  3874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3875. }
  3876. }
  3877. }
  3878. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3879. {
  3880. for (int index = 0; index < CCS_QUANTITY; index++)
  3881. {
  3882. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3883. {
  3884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3885. }
  3886. }
  3887. }
  3888. else if(gunType[gun_index] == 'G')
  3889. {
  3890. for (int index = 0; index < GB_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3893. {
  3894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3895. }
  3896. }
  3897. }
  3898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3904. } // END FOR DC CASE
  3905. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3906. {
  3907. 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\"}]}]}]"
  3908. ,gun_index+1
  3909. ,MESSAGE_TYPE_CALL
  3910. ,guid
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3916. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3959. );
  3960. }
  3961. else
  3962. {
  3963. 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\"}]}]}]"
  3964. ,gun_index+1
  3965. ,MESSAGE_TYPE_CALL
  3966. ,guid
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3972. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4008. );
  4009. }
  4010. #if 1 // for TempStopTransaction
  4011. //Delete TempStopTransaction
  4012. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4013. {
  4014. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4015. }
  4016. #endif
  4017. #if 1
  4018. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4019. if(hashmap_operation(0, guid, tempdata) == 1)
  4020. {
  4021. result = PASS;
  4022. DEBUG_INFO("StopTransaction mapitem pass\n");
  4023. }
  4024. #endif
  4025. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4026. /*
  4027. if(GetTransactionQueueNum() == 1)
  4028. {
  4029. LWS_Send(queuedata+2);
  4030. }*/
  4031. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4032. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4033. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4034. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4035. {
  4036. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4037. }
  4038. //for test
  4039. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4040. return result;
  4041. }
  4042. int sendMeterValuesRequest(int gun_index)
  4043. {
  4044. mtrace();
  4045. int result = FAIL;
  4046. // char message[1500]={0};
  4047. char guid[37]={0};
  4048. //int idx_sample=0;
  4049. //int length = 0;
  4050. char tempdata[65]={0};
  4051. int tempIndex = 0;
  4052. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4053. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4054. /*
  4055. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4056. {
  4057. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4058. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4059. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4060. return result;
  4061. }*/
  4062. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4063. {
  4064. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4065. }
  4066. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4067. //set value
  4068. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4069. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4070. random_uuid(guid);
  4071. //UTC Date time
  4072. struct timeval tmnow;
  4073. struct tm *tm;
  4074. char buf[28];//, usec_buf[6];
  4075. gettimeofday(&tmnow, NULL);
  4076. time_t t;
  4077. t = time(NULL);
  4078. /*UTC time and date*/
  4079. tm = gmtime(&t);
  4080. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4082. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4083. //idx_sample=0;
  4084. //********************************(1)Current.Export************************************************/
  4085. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4086. if(gunType[gun_index] == 'J')
  4087. {
  4088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4089. {
  4090. tempIndex = ((gun_index==2) ? 1: 0);
  4091. }
  4092. else
  4093. {
  4094. tempIndex = gun_index;
  4095. }
  4096. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4097. {
  4098. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4099. {
  4100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4101. }
  4102. }
  4103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4104. }
  4105. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4106. {
  4107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4108. {
  4109. tempIndex = ((gun_index==2) ? 1: 0);
  4110. }
  4111. else
  4112. {
  4113. tempIndex = gun_index;
  4114. }
  4115. for (int index = 0; index < CCS_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4118. {
  4119. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4120. }
  4121. }
  4122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4123. }
  4124. else if(gunType[gun_index] == 'G')
  4125. {
  4126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4127. {
  4128. tempIndex = ((gun_index==2) ? 1: 0);
  4129. }
  4130. else
  4131. {
  4132. tempIndex = gun_index;
  4133. }
  4134. for (int index = 0; index < GB_QUANTITY; index++)
  4135. {
  4136. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4137. {
  4138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4139. }
  4140. }
  4141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4142. }
  4143. else
  4144. {
  4145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4146. {
  4147. tempIndex = 2;
  4148. }
  4149. else
  4150. {
  4151. tempIndex = gun_index;
  4152. }
  4153. for (int index = 0; index < AC_QUANTITY; index++)
  4154. {
  4155. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4156. {
  4157. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4158. }
  4159. }
  4160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4161. }
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4165. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4168. //idx_sample=1;
  4169. //********************************(2)Energy.Active.Import.Register ************************************************/
  4170. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4171. if(gunType[gun_index] == 'J')
  4172. {
  4173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4174. {
  4175. tempIndex = ((gun_index==2) ? 1: 0);
  4176. }
  4177. else
  4178. {
  4179. tempIndex = gun_index;
  4180. }
  4181. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4182. {
  4183. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4184. {
  4185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4186. }
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4189. }
  4190. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4191. {
  4192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4193. {
  4194. tempIndex = ((gun_index==2) ? 1: 0);
  4195. }
  4196. else
  4197. {
  4198. tempIndex = gun_index;
  4199. }
  4200. for (int index = 0; index < CCS_QUANTITY; index++)
  4201. {
  4202. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4203. {
  4204. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4205. }
  4206. }
  4207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4208. }
  4209. else if(gunType[gun_index] == 'G')
  4210. {
  4211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4212. {
  4213. tempIndex = ((gun_index==2) ? 1: 0);
  4214. }
  4215. else
  4216. {
  4217. tempIndex = gun_index;
  4218. }
  4219. for (int index = 0; index < GB_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4222. {
  4223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4224. }
  4225. }
  4226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4227. }
  4228. else
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4231. {
  4232. tempIndex = 2;
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < AC_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4243. }
  4244. }
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4246. }
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4250. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4253. //idx_sample=2;
  4254. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4256. if(gunType[gun_index] == 'J')
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4259. {
  4260. tempIndex = ((gun_index==2) ? 1: 0);
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4271. }
  4272. } // END OF FOR CHAdeMO_QUANTITY
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4274. }
  4275. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4276. {
  4277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4278. {
  4279. tempIndex = ((gun_index==2) ? 1: 0);
  4280. }
  4281. else
  4282. {
  4283. tempIndex = gun_index;
  4284. }
  4285. for (int index = 0; index < CCS_QUANTITY; index++)
  4286. {
  4287. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4289. {
  4290. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4292. }
  4293. } // END OF CCS_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4295. }
  4296. else if(gunType[gun_index] == 'G')
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4299. {
  4300. tempIndex = ((gun_index==2) ? 1: 0);
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < GB_QUANTITY; index++)
  4307. {
  4308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4309. {
  4310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4311. }
  4312. } // END OF GB_QUANTITY
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4314. }
  4315. else
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4318. {
  4319. tempIndex = 2;
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < AC_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4328. {
  4329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4330. }
  4331. }
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4333. }
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4337. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4340. //idx_sample=3;
  4341. //********************************(4)Power.Active.Export************************************************/
  4342. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4343. if(gunType[gun_index] == 'J')
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4346. {
  4347. tempIndex = ((gun_index==2) ? 1: 0);
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4354. {
  4355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4356. {
  4357. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4358. }
  4359. } // END OF FOR
  4360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4361. }
  4362. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4363. {
  4364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4365. {
  4366. tempIndex = ((gun_index==2) ? 1: 0);
  4367. }
  4368. else
  4369. {
  4370. tempIndex = gun_index;
  4371. }
  4372. for (int index = 0; index < CCS_QUANTITY; index++)
  4373. {
  4374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4375. {
  4376. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4377. }
  4378. }
  4379. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4380. }
  4381. else if(gunType[gun_index] == 'G')
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4384. {
  4385. tempIndex = ((gun_index==2) ? 1: 0);
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < GB_QUANTITY; index++)
  4392. {
  4393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4394. {
  4395. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4396. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4397. }
  4398. }
  4399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4400. }
  4401. else
  4402. {
  4403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4404. {
  4405. tempIndex = 2;
  4406. }
  4407. else
  4408. {
  4409. tempIndex = gun_index;
  4410. }
  4411. for (int index = 0; index < AC_QUANTITY; index++)
  4412. {
  4413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4414. {
  4415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4416. }
  4417. }
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4419. }
  4420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4423. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4426. //idx_sample=4;
  4427. //***********************************************(5)VOLTAGE******************************************************/
  4428. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4429. if(gunType[gun_index] == 'J')
  4430. {
  4431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4432. {
  4433. tempIndex = ((gun_index==2) ? 1: 0);
  4434. }
  4435. else
  4436. {
  4437. tempIndex = gun_index;
  4438. }
  4439. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4440. {
  4441. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4442. {
  4443. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4444. }
  4445. }
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4447. }
  4448. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CCS_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4461. {
  4462. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4463. }
  4464. }
  4465. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4466. }
  4467. else if(gunType[gun_index] == 'G')
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4470. {
  4471. tempIndex = ((gun_index==2) ? 1: 0);
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < GB_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4480. {
  4481. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4482. }
  4483. }
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4485. }
  4486. else
  4487. {
  4488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4489. {
  4490. tempIndex = 2;
  4491. }
  4492. else
  4493. {
  4494. tempIndex = gun_index;
  4495. }
  4496. for (int index = 0; index < AC_QUANTITY; index++)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4499. {
  4500. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4501. }
  4502. }
  4503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4504. }
  4505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4508. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4511. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4512. {
  4513. //idx_sample=5;
  4514. //sampledValue = NULL;
  4515. //***********************************************(6)SOC******************************************************/
  4516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4517. {
  4518. tempIndex = ((gun_index==2) ? 1: 0);
  4519. }
  4520. else
  4521. {
  4522. tempIndex = gun_index;
  4523. }
  4524. if(gunType[gun_index] == 'J')
  4525. {
  4526. //tempIndex = ((gun_index==2) ? 1: 0);
  4527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4528. {
  4529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4530. {
  4531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4532. }
  4533. }
  4534. }
  4535. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4536. {
  4537. //tempIndex = ((gun_index==2) ? 1: 0);
  4538. for (int index = 0; index < CCS_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4543. }
  4544. }
  4545. }
  4546. else if(gunType[gun_index] == 'G')
  4547. {
  4548. //tempIndex = ((gun_index==2) ? 1: 0);
  4549. for (int index = 0; index < GB_QUANTITY; index++)
  4550. {
  4551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4552. {
  4553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4554. }
  4555. }
  4556. }
  4557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4563. }
  4564. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4565. {
  4566. 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\"}]}]}]"
  4567. ,gun_index + 1
  4568. ,MESSAGE_TYPE_CALL
  4569. ,guid
  4570. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4571. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4572. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4615. );
  4616. }
  4617. else
  4618. {
  4619. 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\"}]}]}]"
  4620. ,gun_index + 1
  4621. ,MESSAGE_TYPE_CALL
  4622. ,guid
  4623. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4624. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4625. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4661. );
  4662. }
  4663. // Put request guid to hash map
  4664. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4665. 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*/)
  4666. {
  4667. result = PASS;
  4668. DEBUG_INFO("MeterValues mapitem pass\n");
  4669. }
  4670. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4671. /*
  4672. if(GetTransactionQueueNum() == 1)
  4673. {
  4674. LWS_Send(queuedata +2);
  4675. }*/
  4676. return result;
  4677. }
  4678. //==========================================
  4679. // send confirm routine
  4680. //==========================================
  4681. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4682. {
  4683. mtrace();
  4684. int result = FAIL;
  4685. char message[100]={0};
  4686. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4687. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4688. LWS_Send(message);
  4689. result = TRUE;
  4690. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4691. return result;
  4692. }
  4693. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4694. {
  4695. mtrace();
  4696. int result = FAIL;
  4697. char message[100]={0};
  4698. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4700. LWS_Send(message);
  4701. result = TRUE;
  4702. return result;
  4703. }
  4704. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4705. {
  4706. mtrace();
  4707. int result = FAIL;
  4708. char message[100]={0};
  4709. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4711. LWS_Send(message);
  4712. result = TRUE;
  4713. return result;
  4714. }
  4715. int sendClearCacheConfirmation(char *uuid,char *payload)
  4716. {
  4717. mtrace();
  4718. int result = FAIL;
  4719. char message[500]={0};
  4720. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4721. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4722. LWS_Send(message);
  4723. return result;
  4724. }
  4725. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4726. {
  4727. mtrace();
  4728. int result = FAIL;
  4729. char message[500]={0};
  4730. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4731. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4732. LWS_Send(message);
  4733. return result;
  4734. }
  4735. int sendDataTransferConfirmation(char *uuid,char *payload)
  4736. {
  4737. mtrace();
  4738. char statusStr[20]={0};
  4739. char dataStr[10]={0};
  4740. char sstr[20]={0};
  4741. int c = 0;
  4742. char *loc;
  4743. int result = FAIL;
  4744. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4745. /**********************status**************************/
  4746. loc = strstr(payload, "status");
  4747. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4748. c = 0;
  4749. while (loc[3+strlen("status")+c] != '\"')
  4750. {
  4751. sstr[c] = loc[3+strlen("status")+c];
  4752. c++;
  4753. }
  4754. sstr[c] = '\0';
  4755. strcpy(statusStr, sstr);
  4756. /**********************data**************************/
  4757. loc = strstr(payload, "data");
  4758. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4759. c = 0;
  4760. while (loc[3+strlen("data")+c] != '\"')
  4761. {
  4762. sstr[c] = loc[3+strlen("data")+c];
  4763. c++;
  4764. }
  4765. sstr[c] = '\0';
  4766. strcpy(dataStr, sstr);
  4767. return result;
  4768. }
  4769. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4770. {
  4771. mtrace();
  4772. int result = FAIL;
  4773. char message[1000]={0};
  4774. int CompositeScheduleIndex = 0;
  4775. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4776. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4777. if(nPeriod == 0)
  4778. {
  4779. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4780. {
  4781. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4782. ,MESSAGE_TYPE_CALLRESULT
  4783. ,uuid
  4784. ,payload
  4785. ,connectorIdInt);
  4786. }
  4787. else
  4788. {
  4789. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4790. ,MESSAGE_TYPE_CALLRESULT
  4791. ,uuid
  4792. ,payload
  4793. ,connectorIdInt
  4794. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4795. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4796. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4797. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4798. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4799. }
  4800. }
  4801. else
  4802. {
  4803. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4804. ,MESSAGE_TYPE_CALLRESULT
  4805. ,uuid
  4806. ,payload
  4807. ,connectorIdInt
  4808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4809. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4810. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4811. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4812. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4813. {
  4814. if (idx_sample == 0)
  4815. {
  4816. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4817. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4818. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4819. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4820. }
  4821. else
  4822. {
  4823. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4824. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4825. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4826. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4827. }
  4828. }
  4829. sprintf(message + strlen(message), "]}}]");
  4830. }
  4831. LWS_Send(message);
  4832. result = TRUE;
  4833. return result;
  4834. }
  4835. int sendGetConfigurationConfirmation(char *uuid)
  4836. {
  4837. mtrace();
  4838. int result = FAIL;
  4839. int MaxKeySupported = 0;
  4840. int sentConfigurationNumber= 0;
  4841. int sentunConfigurationNumber= 0;
  4842. char message[4000]={0};
  4843. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4844. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4845. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4846. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4847. ,MESSAGE_TYPE_CALLRESULT
  4848. ,uuid );
  4849. //configuration key
  4850. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4851. {
  4852. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4853. {
  4854. if (sentConfigurationNumber == 0)
  4855. {
  4856. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4857. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4858. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4859. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4860. }
  4861. else
  4862. {
  4863. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4864. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4865. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4866. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4867. }
  4868. sentConfigurationNumber = sentConfigurationNumber + 1;
  4869. }
  4870. }
  4871. sprintf(message + strlen(message), "]");
  4872. if(UnknownKeynum != 0)
  4873. {
  4874. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4875. //unkown key
  4876. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4877. {
  4878. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4879. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4880. if(sentunConfigurationNumber == 0)
  4881. {
  4882. sprintf(message + strlen(message), "\"%s\""
  4883. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4884. }
  4885. else
  4886. {
  4887. sprintf(message + strlen(message), ",\"%s\""
  4888. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4889. }
  4890. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4891. }
  4892. sprintf(message + strlen(message), "]");
  4893. }
  4894. sprintf(message + strlen(message), "}]");
  4895. LWS_Send(message);
  4896. return result;
  4897. }
  4898. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4899. {
  4900. mtrace();
  4901. int result = FAIL;
  4902. char message[400]={0};
  4903. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4904. if(strcmp(payload,"")==0)
  4905. {
  4906. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4907. }
  4908. else
  4909. {
  4910. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4911. }
  4912. LWS_Send(message);
  4913. result = TRUE;
  4914. return result;
  4915. }
  4916. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4917. {
  4918. mtrace();
  4919. int result = FAIL;
  4920. char message[80]={0};
  4921. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4922. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4923. LWS_Send(message);
  4924. result = TRUE;
  4925. return result;
  4926. }
  4927. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4928. {
  4929. mtrace();
  4930. int result = FAIL;
  4931. char message[80]={0};
  4932. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4933. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4934. LWS_Send(message);
  4935. result = TRUE;
  4936. return result;
  4937. }
  4938. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4939. {
  4940. mtrace();
  4941. int result = FAIL;
  4942. char message[80]={0};
  4943. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4945. LWS_Send(message);
  4946. result = TRUE;
  4947. return result;
  4948. }
  4949. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4950. {
  4951. mtrace();
  4952. int result = FAIL;
  4953. char message[80]={0};
  4954. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4955. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4957. LWS_Send(message);
  4958. result = TRUE;
  4959. return result;
  4960. }
  4961. int sendResetConfirmation(char *uuid,char *payload)
  4962. {
  4963. mtrace();
  4964. int result = FAIL;
  4965. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4966. char message[80]={0};
  4967. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4968. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4969. LWS_Send(message);
  4970. result = TRUE;
  4971. return result;
  4972. }
  4973. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4974. {
  4975. mtrace();
  4976. int result = FAIL;
  4977. char message[500]={0};
  4978. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4979. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4980. LWS_Send(message);
  4981. result = TRUE;
  4982. return result;
  4983. }
  4984. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4985. {
  4986. mtrace();
  4987. int result = FAIL;
  4988. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4989. char message[80]={0};
  4990. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4992. LWS_Send(message);
  4993. result = TRUE;
  4994. return result;
  4995. }
  4996. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4997. {
  4998. mtrace();
  4999. int result = FAIL;
  5000. char message[80]={0};
  5001. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5003. LWS_Send(message);
  5004. result = TRUE;
  5005. return result;
  5006. }
  5007. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5008. {
  5009. mtrace();
  5010. int result = FAIL;
  5011. char message[80]={0};
  5012. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5013. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5015. LWS_Send(message);
  5016. result = TRUE;
  5017. return result;
  5018. }
  5019. int sendUpdateFirmwareConfirmation(char *uuid)
  5020. {
  5021. mtrace();
  5022. int result = FAIL;
  5023. char message[60]={0};
  5024. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5025. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5026. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5027. LWS_Send(message);
  5028. result = TRUE;
  5029. return result;
  5030. }
  5031. //==========================================
  5032. // send CallError routine
  5033. //==========================================
  5034. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5035. {
  5036. mtrace();
  5037. char message[220]={0};
  5038. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5039. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5040. LWS_Send(message);
  5041. }
  5042. //==========================================
  5043. // Handle server request routine Start
  5044. //==========================================
  5045. int handleCancelReservationRequest(char *uuid, char *payload)
  5046. {
  5047. mtrace();
  5048. int result = FAIL;
  5049. int gunNO = 0;
  5050. int reservationIdInt =0;
  5051. char comfirmstr[20];
  5052. DEBUG_INFO("handleCancelReservationRequest...\n");
  5053. json_object *CancelReservation;
  5054. CancelReservation = json_tokener_parse(payload);
  5055. if(!is_error(CancelReservation))
  5056. {
  5057. // Required data
  5058. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5059. }
  5060. json_object_put(CancelReservation);
  5061. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5062. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5063. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5064. //check Transaction active
  5065. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5067. {
  5068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5069. {
  5070. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5071. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5072. if(gunType[2] == 'J')
  5073. {
  5074. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5075. }
  5076. else
  5077. {
  5078. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5079. }
  5080. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5081. goto end;
  5082. }
  5083. }
  5084. for (int index = 0; index < CCS_QUANTITY; index++)
  5085. {
  5086. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5087. {
  5088. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5089. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5090. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5091. {
  5092. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5093. }
  5094. else
  5095. {
  5096. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5097. }
  5098. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5099. goto end;
  5100. }
  5101. }
  5102. for (int index = 0; index < GB_QUANTITY; index++)
  5103. {
  5104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5105. {
  5106. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5107. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5108. if(gunType[2] == 'G')
  5109. {
  5110. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5111. }
  5112. else
  5113. {
  5114. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5115. }
  5116. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5117. goto end;
  5118. }
  5119. }
  5120. for (int index = 0; index < AC_QUANTITY; index++)
  5121. {
  5122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5123. {
  5124. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5125. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5127. {
  5128. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5129. }
  5130. else
  5131. {
  5132. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5133. }
  5134. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5135. goto end;
  5136. }
  5137. }
  5138. //The reservationId does NOT match the reservationId
  5139. sendCancelReservationConfirmation(uuid, comfirmstr);
  5140. end:
  5141. // Fill in ocpp packet uuid
  5142. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5143. return result;
  5144. }
  5145. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5146. {
  5147. mtrace();
  5148. int result = FAIL;
  5149. int gunIndex = 0;
  5150. char typeStr[16]={0};
  5151. char comfirmstr[20];
  5152. int specificId = FALSE;
  5153. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5154. json_object *ChangeAvailability;
  5155. ChangeAvailability = json_tokener_parse(payload);
  5156. if(!is_error(ChangeAvailability))
  5157. {
  5158. // Required data
  5159. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5160. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5161. }
  5162. json_object_put(ChangeAvailability);
  5163. if(gunIndex != 0)
  5164. {
  5165. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5166. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5167. }
  5168. else
  5169. {
  5170. for(int i=0; i < gunTotalNumber; i++)
  5171. {
  5172. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5173. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5174. }
  5175. }
  5176. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5177. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5178. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5179. {
  5180. specificId = TRUE;
  5181. }
  5182. if(specificId == FALSE)
  5183. goto end;
  5184. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5185. {
  5186. //----------------------gunIndex is 0 ------------------------------------------------//
  5187. if(gunIndex == 0)
  5188. {
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5190. {
  5191. for(int i=0; i < gunTotalNumber; i++)
  5192. {
  5193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5194. {
  5195. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5196. {
  5197. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5198. {
  5199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5200. goto end;
  5201. }
  5202. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5203. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5204. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5205. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5206. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5207. {
  5208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5209. goto end;
  5210. }
  5211. }
  5212. }//END FOR CHAdeMO_QUANTITY
  5213. for (int index = 0; index < CCS_QUANTITY; index++)
  5214. {
  5215. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5216. {
  5217. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5218. {
  5219. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5220. goto end;
  5221. }
  5222. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5223. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5224. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5225. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5226. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5227. {
  5228. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5229. goto end;
  5230. }
  5231. }
  5232. }//END FOR CCS_QUANTITY
  5233. for (int index = 0; index < GB_QUANTITY; index++)
  5234. {
  5235. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5236. {
  5237. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5238. {
  5239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5240. goto end;
  5241. }
  5242. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5243. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5244. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5245. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5246. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5247. {
  5248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5249. goto end;
  5250. }
  5251. }
  5252. }// END FOR GB_QUANTITY
  5253. for (int index = 0; index < AC_QUANTITY; index++)
  5254. {
  5255. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5256. {
  5257. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5258. {
  5259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5260. goto end;
  5261. }
  5262. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5266. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5267. {
  5268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5269. goto end;
  5270. }
  5271. }
  5272. }//END FOR AC_QUANTITY
  5273. }// END FOR gunTotalNumber
  5274. }
  5275. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5276. {
  5277. for(int i=0; i < gunTotalNumber; i++)
  5278. {
  5279. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5280. {
  5281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5282. goto end;
  5283. }
  5284. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5285. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5286. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5287. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5288. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5289. {
  5290. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5291. goto end;
  5292. }
  5293. }
  5294. }
  5295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5296. goto end;
  5297. }
  5298. //----------------------gunIndex is not 0 ------------------------------------------------//
  5299. //check Transaction active
  5300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5301. {
  5302. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5303. {
  5304. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5305. {
  5306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5307. goto end;
  5308. }
  5309. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5312. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5313. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5314. {
  5315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5316. goto end;
  5317. }
  5318. else
  5319. {
  5320. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5322. goto end;
  5323. }
  5324. }
  5325. }//END FOR CHAdeMO_QUANTITY
  5326. for (int index = 0; index < CCS_QUANTITY; index++)
  5327. {
  5328. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5329. {
  5330. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5331. {
  5332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5333. goto end;
  5334. }
  5335. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5336. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5337. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5338. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5339. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5340. {
  5341. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5342. goto end;
  5343. }
  5344. else
  5345. {
  5346. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5348. goto end;
  5349. }
  5350. }
  5351. }//END FOR CCS_QUANTITY
  5352. for (int index = 0; index < GB_QUANTITY; index++)
  5353. {
  5354. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5355. {
  5356. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5357. {
  5358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5359. goto end;
  5360. }
  5361. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5362. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5363. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5364. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5365. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5366. {
  5367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5368. goto end;
  5369. }
  5370. else
  5371. {
  5372. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5374. goto end;
  5375. }
  5376. }
  5377. }// END FOR GB_QUANTITY
  5378. for (int index = 0; index < AC_QUANTITY; index++)
  5379. {
  5380. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5381. {
  5382. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5383. {
  5384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5385. goto end;
  5386. }
  5387. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5388. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5389. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5390. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5391. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5392. {
  5393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5394. goto end;
  5395. }
  5396. else
  5397. {
  5398. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5400. goto end;
  5401. }
  5402. }
  5403. }//END FOR AC_QUANTITY
  5404. }//END FOR AvailabilityTypeStr[Inoperative]
  5405. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5406. {
  5407. //----------------------gunIndex is 0 ------------------------------------------------//
  5408. if(gunIndex == 0)
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5411. {
  5412. for(int i=0; i < gunTotalNumber; i++)
  5413. {
  5414. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5415. {
  5416. 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
  5417. {
  5418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5419. goto end;
  5420. }
  5421. }//END FOR CHAdeMO_QUANTITY
  5422. for (int index = 0; index < CCS_QUANTITY; index++)
  5423. {
  5424. 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
  5425. {
  5426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5427. goto end;
  5428. }
  5429. }//END FOR CCS_QUANTITY
  5430. for (int index = 0; index < GB_QUANTITY; index++)
  5431. {
  5432. 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
  5433. {
  5434. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5436. goto end;
  5437. }
  5438. }// END FOR GB_QUANTITY
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. 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
  5442. {
  5443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5444. goto end;
  5445. }
  5446. }//END FOR CHAdeMO_QUANTITY
  5447. }// END FOR gunTotalNumber
  5448. }
  5449. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5450. {
  5451. for(int i=0; i < gunTotalNumber; i++)
  5452. {
  5453. for (int index = 0; index < AC_QUANTITY; index++)
  5454. {
  5455. 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
  5456. {
  5457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5458. goto end;
  5459. }
  5460. }//END FOR CHAdeMO_QUANTITY
  5461. } // END FOR gunTotalNumber
  5462. }
  5463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5464. goto end;
  5465. }
  5466. //----------------------gunIndex is not 0 ------------------------------------------------//
  5467. //check Transaction active
  5468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5469. {
  5470. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5471. {
  5472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5473. goto end;
  5474. }
  5475. }//END FOR CHAdeMO_QUANTITY
  5476. for (int index = 0; index < CCS_QUANTITY; index++)
  5477. {
  5478. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5479. {
  5480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5481. goto end;
  5482. }
  5483. }//END FOR CCS_QUANTITY
  5484. for (int index = 0; index < GB_QUANTITY; index++)
  5485. {
  5486. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5487. {
  5488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5489. goto end;
  5490. }
  5491. }// END FOR GB_QUANTITY
  5492. for (int index = 0; index < AC_QUANTITY; index++)
  5493. {
  5494. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5495. {
  5496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5497. goto end;
  5498. }
  5499. }//END FOR AC_QUANTITY
  5500. }//END FOR AvailabilityTypeStr[Operative]
  5501. end:
  5502. if(gunIndex != 0)
  5503. {
  5504. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5505. }
  5506. else
  5507. {
  5508. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5509. }
  5510. if(gunIndex != 0)
  5511. {
  5512. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5513. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5514. }
  5515. else
  5516. {
  5517. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5518. {
  5519. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5520. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5521. }
  5522. }
  5523. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5524. return result;
  5525. }
  5526. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5527. {
  5528. mtrace();
  5529. int result = FAIL;
  5530. char keystr[40]={0};
  5531. char valuestr[100]={0};
  5532. char comfirmstr[20]={0};
  5533. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5534. json_object *ChangeConfiguration;
  5535. ChangeConfiguration = json_tokener_parse(payload);
  5536. if(!is_error(ChangeConfiguration))
  5537. {
  5538. // Required data
  5539. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5540. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5541. }
  5542. json_object_put(ChangeConfiguration);
  5543. if((uuid==NULL) || (payload ==NULL) )
  5544. {
  5545. DEBUG_ERROR("Payload is null\n");
  5546. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5547. }
  5548. else
  5549. {
  5550. int status = setKeyValue(keystr, valuestr);
  5551. switch(status)
  5552. {
  5553. case ConfigurationStatus_Accepted:
  5554. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5555. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5556. StoreConfigurationTable();
  5557. break;
  5558. case ConfigurationStatus_Rejected:
  5559. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5560. break;
  5561. case RebootRequired:
  5562. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5563. StoreConfigurationTable();
  5564. break;
  5565. case NotSupported:
  5566. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5567. break;
  5568. default:
  5569. break;
  5570. }
  5571. }
  5572. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5573. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5574. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5575. {
  5576. ChageWebSocketPingInterval(atoi(valuestr));
  5577. }
  5578. return result;
  5579. }
  5580. int handleClearCacheRequest(char *uuid, char *payload)
  5581. {
  5582. mtrace();
  5583. int result = FAIL;
  5584. char comfirmstr[20];
  5585. int fd;
  5586. char rmFileCmd[100]={0};
  5587. struct stat stats;
  5588. DEBUG_INFO("handleClearCacheRequest...\n");
  5589. stat("/Storage/OCPP", &stats);
  5590. // Check for directory existence
  5591. if (S_ISDIR(stats.st_mode) == 1)
  5592. {}
  5593. else
  5594. {
  5595. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5596. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5597. system(rmFileCmd);
  5598. }
  5599. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5600. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5601. {
  5602. DEBUG_INFO("AuthorizationCache file exist.\n");
  5603. }
  5604. else
  5605. {
  5606. DEBUG_INFO("AuthorizationCache file not exist\n");
  5607. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5608. if(log == NULL)
  5609. {
  5610. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5611. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5612. goto end;
  5613. }
  5614. else
  5615. {
  5616. fclose(log);
  5617. }
  5618. }
  5619. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5620. {
  5621. DEBUG_INFO("open AuthorizationCache file failed\n");
  5622. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5623. }
  5624. else
  5625. {
  5626. DEBUG_INFO("open AuthorizationCache file successful\n");
  5627. ftruncate(fd,0);
  5628. lseek(fd,0,SEEK_SET);
  5629. close(fd);
  5630. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5631. }
  5632. end:
  5633. sendClearCacheConfirmation(uuid, comfirmstr);
  5634. return result;
  5635. }
  5636. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5637. {
  5638. mtrace();
  5639. int result = FAIL;
  5640. int resultRename;
  5641. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5642. char chargingProfilePurposeStr[26]={0};
  5643. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5644. char tempchargingProfilePurposeStr[26]={0};
  5645. char sstr[160]={0};
  5646. char str[100]={0};
  5647. int c = 0;
  5648. char *loc;
  5649. char fname[200]={0};
  5650. char comfirmstr[20]={0};
  5651. char word[1600]={0};
  5652. int clearflag = FALSE;
  5653. int chargingProfileIdIsNULL = FALSE;
  5654. int connectorIsNULL = FALSE;
  5655. int chargingProfilePurposeIsNULL = FALSE;
  5656. int stackLevelIsNULL = FALSE;
  5657. //int GotoEnd = FALSE;
  5658. FILE *fptr1, *fptr2;
  5659. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5660. int n_chargingProfile=0;
  5661. int isEmptyFile = FALSE;
  5662. char sLineWord[1600]={0};
  5663. char chargingProfiles[10][100]={0};
  5664. int ChargeProfileCount = 0;
  5665. char ch;
  5666. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5667. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5668. json_object *ClearChargingProfile;
  5669. ClearChargingProfile = json_tokener_parse(payload);
  5670. if(!is_error(ClearChargingProfile))
  5671. {
  5672. // Optional data
  5673. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5674. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5675. else
  5676. chargingProfileIdIsNULL = TRUE;
  5677. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5678. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5679. else
  5680. connectorIsNULL = TRUE;
  5681. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5682. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5683. else
  5684. chargingProfilePurposeIsNULL = TRUE;
  5685. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5686. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5687. else
  5688. stackLevelIsNULL = TRUE;
  5689. }
  5690. json_object_put(ClearChargingProfile);
  5691. if(connectorIsNULL == FALSE)
  5692. {
  5693. switch(connectorIdInt)
  5694. {
  5695. case 0:
  5696. if(chargingProfilePurposeIsNULL == TRUE)
  5697. {
  5698. int l = 0;
  5699. strcpy(fname, ChargePointMaxProfile_JSON);
  5700. if((access(fname,F_OK))!=-1)
  5701. {
  5702. strcpy(chargingProfiles[l], fname);
  5703. l = l + 1;
  5704. }
  5705. strcpy(fname, TxDefaultProfile_0_JSON);
  5706. if((access(fname,F_OK))!=-1)
  5707. {
  5708. strcpy(chargingProfiles[l], fname);
  5709. l = l + 1;
  5710. }
  5711. ChargeProfileCount = l;
  5712. }
  5713. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5714. {
  5715. strcpy(fname, ChargePointMaxProfile_JSON);
  5716. if((access(fname,F_OK))!=-1)
  5717. {
  5718. strcpy(chargingProfiles[0], fname);
  5719. ChargeProfileCount = 1;
  5720. }
  5721. }
  5722. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5723. {
  5724. strcpy(fname, TxDefaultProfile_0_JSON);
  5725. if((access(fname,F_OK))!=-1)
  5726. {
  5727. strcpy(chargingProfiles[0], fname);
  5728. ChargeProfileCount = 1;
  5729. }
  5730. }
  5731. break;
  5732. default:
  5733. if(chargingProfilePurposeIsNULL == TRUE)
  5734. {
  5735. int m = 0;
  5736. memset(fname, 0, ARRAY_SIZE(fname));
  5737. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5738. if((access(fname,F_OK))!=-1)
  5739. {
  5740. strcpy(chargingProfiles[m], fname);
  5741. m = m + 1;
  5742. }
  5743. memset(fname, 0, ARRAY_SIZE(fname));
  5744. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5745. if((access(fname,F_OK))!=-1)
  5746. {
  5747. strcpy(chargingProfiles[m], fname);
  5748. m = m + 1;
  5749. }
  5750. ChargeProfileCount = m;
  5751. }
  5752. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5753. {
  5754. //strcpy(fname, TxDefaultProfile_1_JSON);
  5755. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5756. if((access(fname,F_OK))!=-1)
  5757. {
  5758. strcpy(chargingProfiles[0], fname);
  5759. ChargeProfileCount = 1;
  5760. }
  5761. }
  5762. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5763. {
  5764. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5765. if((access(fname,F_OK))!=-1)
  5766. {
  5767. strcpy(chargingProfiles[0], fname);
  5768. ChargeProfileCount = 1;
  5769. }
  5770. //strcpy(fname, TxProfile_1_JSON);
  5771. }
  5772. //strcpy(fname, ChargePointMaxProfile_JSON );
  5773. break;
  5774. }
  5775. }
  5776. else // Check all Charging Profiles
  5777. {
  5778. int i = 0;
  5779. char fnametemp[200]={0};
  5780. ChargeProfileCount = 0;
  5781. //Check ChargePointMaxProfile.json exit
  5782. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5783. {
  5784. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5785. i = i + 1;
  5786. }
  5787. //Check TxDefaultProfile_0.json exit
  5788. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5789. {
  5790. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5791. i = i + 1;
  5792. }
  5793. //Check TxDefaultProfile_%d.json
  5794. for(int j=1; j <= gunTotalNumber; j++)
  5795. {
  5796. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5797. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5798. if((access(fnametemp,F_OK))!=-1)
  5799. {
  5800. strcpy(chargingProfiles[i], fnametemp);
  5801. i = i + 1;
  5802. }
  5803. }
  5804. //Check TxProfile_%d.json
  5805. for(int j=1; j <= gunTotalNumber; j++)
  5806. {
  5807. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5808. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5809. if((access(fnametemp,F_OK))!=-1)
  5810. {
  5811. strcpy(chargingProfiles[i], fnametemp);
  5812. i = i + 1;
  5813. }
  5814. }
  5815. ChargeProfileCount = i;
  5816. }// End connectorIsNULL is TRUE
  5817. if(ChargeProfileCount == 0)
  5818. {
  5819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5820. goto end;
  5821. }
  5822. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5823. {
  5824. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5825. goto end;
  5826. }
  5827. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5828. {
  5829. memset(str, 0, ARRAY_SIZE(str));
  5830. // clear temp file
  5831. sprintf(str,"rm -f %s",temp);
  5832. system(str);
  5833. for(int k=0; k < ChargeProfileCount; k++)
  5834. {
  5835. memset(str, 0, ARRAY_SIZE(str));
  5836. //clear file in C
  5837. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5838. system(str);
  5839. }
  5840. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5841. goto end;
  5842. }
  5843. else if(connectorIsNULL == TRUE)
  5844. {
  5845. for(int k=0; k < ChargeProfileCount; k++)
  5846. {
  5847. fptr1 = fopen(chargingProfiles[k], "r");
  5848. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5849. //Check Charging Profile Count
  5850. while(fscanf(fptr1, "%s", word) != EOF)
  5851. {
  5852. //DEBUG_INFO("word=%s\n",word);
  5853. if(strstr(word, "chargingProfileId")!= NULL)
  5854. {
  5855. //DEBUG_INFO("test chargingProfileId \n");
  5856. n_chargingProfile = n_chargingProfile + 1;
  5857. //DEBUG_INFO("chargingProfileId Found\n");
  5858. }
  5859. }
  5860. rewind(fptr1);
  5861. //search Charging Profile Element
  5862. //int i= 0;
  5863. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5864. {
  5865. //------------------------tempconnectorIdInt------------------------//
  5866. loc = strstr(sLineWord, "connectorId");
  5867. c = 0;
  5868. memset(sstr ,0, sizeof(sstr) );
  5869. while (loc[strlen("connectorId")+2+c] != ',')
  5870. {
  5871. sstr[c] = loc[strlen("connectorId")+2+c];
  5872. c++;
  5873. }
  5874. sstr[c] = '\0';
  5875. tempconnectorIdInt = atoi(sstr);
  5876. printf("file's gun number is %d\n", tempconnectorIdInt);
  5877. //--------------------------chargingProfileId--------------------//
  5878. c = 0;
  5879. loc = strstr(sLineWord, "chargingProfileId");
  5880. memset(sstr ,0, ARRAY_SIZE(sstr));
  5881. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5882. {
  5883. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5885. c++;
  5886. }
  5887. sstr[c] = '\0';
  5888. tempchargingProfileIdInt = atoi(sstr);
  5889. //stackLevel
  5890. c = 0;
  5891. loc = strstr(sLineWord, "stackLevel");
  5892. memset(sstr ,0, ARRAY_SIZE(sstr));
  5893. while (loc[strlen("stackLevel")+2+c] != ',')
  5894. {
  5895. sstr[c] = loc[strlen("stackLevel")+2+c];
  5896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5897. c++;
  5898. }
  5899. sstr[c] = '\0';
  5900. tempstackLevelInt = atoi(sstr);
  5901. c = 0;
  5902. loc = strstr(sLineWord, "chargingProfilePurpose");
  5903. memset(sstr ,0, ARRAY_SIZE(sstr));
  5904. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5905. {
  5906. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5907. c++;
  5908. }
  5909. sstr[c] = '\0';
  5910. strcpy(tempchargingProfilePurposeStr, sstr);
  5911. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5912. {
  5913. //------- not write to fptr2-------//
  5914. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5915. //clearflag = TRUE;
  5916. }
  5917. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5918. {
  5919. //------- not write to fptr2-------//
  5920. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5921. }
  5922. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5923. {
  5924. //------- not write to fptr2-------//
  5925. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5926. }
  5927. else
  5928. {
  5929. fprintf(fptr2, sLineWord);//writing data into file
  5930. }
  5931. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5932. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5933. if(clearflag == TRUE)
  5934. {
  5935. fclose(fptr1);
  5936. fclose(fptr2);
  5937. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5938. system(str);
  5939. // clear temp file
  5940. sprintf(str,"rm -f %s",temp);
  5941. system(str);
  5942. }
  5943. else
  5944. {
  5945. fclose(fptr1);
  5946. fclose(fptr2);
  5947. memset(str, 0, ARRAY_SIZE(str));
  5948. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5949. system(str);
  5950. resultRename = rename(temp, chargingProfiles[k]);
  5951. if(resultRename == 0)
  5952. {
  5953. DEBUG_INFO("File ChargingProfile renamed successfully");
  5954. }
  5955. else
  5956. {
  5957. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5958. }
  5959. if(comfirmstr[0]== 0)
  5960. {
  5961. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5962. }
  5963. //Check chargingProfile is empty file
  5964. /*------ Read the file ----------------*/
  5965. fptr1=fopen(chargingProfiles[k],"r");
  5966. ch=fgetc(fptr1);
  5967. rewind(fptr1);
  5968. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5969. if(ch!=EOF)
  5970. {
  5971. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5972. {
  5973. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5974. if(sLineWord[0]=='\0')
  5975. {
  5976. isEmptyFile = TRUE;
  5977. break;
  5978. }
  5979. else
  5980. {
  5981. isEmptyFile = FALSE;
  5982. break;
  5983. }
  5984. }
  5985. }
  5986. fclose(fptr1);
  5987. if(isEmptyFile == TRUE)
  5988. {
  5989. memset(str, 0, ARRAY_SIZE(str));
  5990. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5991. system(str);
  5992. }
  5993. }
  5994. }// End of while(int k=0; k < ChargePointCount; k++)
  5995. }
  5996. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5997. {
  5998. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5999. for(int k=0; k < ChargeProfileCount; k++)
  6000. {
  6001. fptr1 = fopen(chargingProfiles[k], "r");
  6002. fptr2 = fopen(temp, "w+");
  6003. //Check Charging Profile Count
  6004. while(fscanf(fptr1, "%s", word) != EOF)
  6005. {
  6006. //DEBUG_INFO("word=%s\n",word);
  6007. if(strstr(word, "chargingProfileId")!= NULL)
  6008. {
  6009. n_chargingProfile = n_chargingProfile + 1;
  6010. }
  6011. }
  6012. rewind(fptr1);
  6013. //search Charging Profile Element
  6014. //int i= 0;
  6015. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6016. {
  6017. //*************************tempconnectorIdInt*********************************/
  6018. loc = strstr(sLineWord, "connectorId");
  6019. c = 0;
  6020. memset(sstr ,0, ARRAY_SIZE(sstr));
  6021. while (loc[strlen("connectorId")+2+c] != ',')
  6022. {
  6023. sstr[c] = loc[strlen("connectorId")+2+c];
  6024. c++;
  6025. }
  6026. sstr[c] = '\0';
  6027. tempconnectorIdInt = atoi(sstr);
  6028. //chargingProfileId
  6029. c = 0;
  6030. loc = strstr(sLineWord, "chargingProfileId");
  6031. memset(sstr ,0, ARRAY_SIZE(sstr));
  6032. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6033. {
  6034. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6036. c++;
  6037. }
  6038. sstr[c] = '\0';
  6039. tempchargingProfileIdInt = atoi(sstr);
  6040. //stackLevel
  6041. c = 0;
  6042. loc = strstr(sLineWord, "stackLevel");
  6043. memset(sstr ,0, ARRAY_SIZE(sstr));
  6044. while (loc[strlen("stackLevel")+2+c] != ',')
  6045. {
  6046. sstr[c] = loc[strlen("stackLevel")+2+c];
  6047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6048. c++;
  6049. }
  6050. sstr[c] = '\0';
  6051. tempstackLevelInt = atoi(sstr);
  6052. c = 0;
  6053. loc = strstr(sLineWord, "chargingProfilePurpose");
  6054. memset(sstr ,0, ARRAY_SIZE(sstr));
  6055. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6056. {
  6057. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. strcpy(tempchargingProfilePurposeStr, sstr);
  6062. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6063. {
  6064. //------- not write to fptr2-------//
  6065. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6066. //clearflag = TRUE;
  6067. }
  6068. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6069. {
  6070. //------- not write to fptr2-------//
  6071. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6072. }
  6073. else if(stackLevelIsNULL == TRUE)
  6074. {
  6075. //Clear Whole File
  6076. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6077. clearflag = TRUE;
  6078. break;
  6079. }
  6080. else
  6081. {
  6082. fprintf(fptr2, sLineWord);//writing data into file
  6083. }
  6084. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6085. }
  6086. if(clearflag == TRUE)
  6087. {
  6088. fclose(fptr1);
  6089. fclose(fptr2);
  6090. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6091. system(str);
  6092. // clear temp file
  6093. sprintf(str,"rm -f %s",temp);
  6094. system(str);
  6095. }
  6096. else
  6097. {
  6098. fclose(fptr1);
  6099. fclose(fptr2);
  6100. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6101. system(str);
  6102. resultRename = rename(temp, chargingProfiles[k]);
  6103. if(resultRename == 0)
  6104. {
  6105. DEBUG_INFO("File ChargingProfile renamed successfully");
  6106. }
  6107. else
  6108. {
  6109. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6110. }
  6111. if(comfirmstr[0]== 0)
  6112. {
  6113. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6114. }
  6115. //Check chargingProfile is empty file
  6116. /*------ Read the file ----------------*/
  6117. fptr1=fopen(chargingProfiles[k],"r");
  6118. ch=fgetc(fptr1);
  6119. rewind(fptr1);
  6120. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6121. if(ch!=EOF)
  6122. {
  6123. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6124. {
  6125. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6126. if(sLineWord[0]=='\0')
  6127. {
  6128. isEmptyFile = TRUE;
  6129. break;
  6130. }
  6131. else
  6132. {
  6133. isEmptyFile = FALSE;
  6134. break;
  6135. }
  6136. }
  6137. }
  6138. fclose(fptr1);
  6139. if(isEmptyFile == TRUE)
  6140. {
  6141. memset(str, 0, ARRAY_SIZE(str));
  6142. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6143. system(str);
  6144. }
  6145. /*------- End of reading ---------------*/
  6146. }
  6147. } // while(int k=0; k < ChargeProfileCount; k++)
  6148. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6149. end:
  6150. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6151. return result;
  6152. }
  6153. void createFirmwareVersionByDataTransfer(void)
  6154. {
  6155. json_object *FirmwareDataTransfer = json_object_new_object();
  6156. // AC & DC model
  6157. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6158. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6159. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6160. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6161. // DC model
  6162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6163. {
  6164. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6165. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6166. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6167. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6168. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6169. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6170. }
  6171. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6172. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6173. {
  6174. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6175. }
  6176. // 4G model
  6177. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6178. {
  6179. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6180. }
  6181. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6182. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6183. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6184. }
  6185. int handleDataTransferRequest(char *uuid, char *payload)
  6186. {
  6187. mtrace();
  6188. json_object *response = json_object_new_object();
  6189. int result = FAIL;
  6190. char tempvendorId[255]={0};
  6191. char tempmessageId[50]={0};
  6192. char tempdata[50]={0};
  6193. char message[2048]={0};
  6194. DEBUG_INFO("handleDataTransferRequest...\n");
  6195. if((uuid != NULL) && (payload != NULL))
  6196. {
  6197. json_object *DataTransfer;
  6198. DataTransfer = json_tokener_parse(payload);
  6199. if(!is_error(DataTransfer))
  6200. {
  6201. // Required data
  6202. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6203. // Optional data
  6204. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6205. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6206. if(json_object_object_get(DataTransfer, "data") != NULL)
  6207. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6208. result = PASS;
  6209. }
  6210. json_object_put(DataTransfer);
  6211. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6212. {
  6213. // Send all moudle firmware version on EVSE
  6214. system("pkill tmate");
  6215. createFirmwareVersionByDataTransfer();
  6216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6217. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6218. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6219. }
  6220. else
  6221. {
  6222. // Can not find valid message id
  6223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6224. }
  6225. }
  6226. else
  6227. {
  6228. // Payload is null
  6229. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6230. }
  6231. LWS_Send(message);
  6232. return result;
  6233. }
  6234. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6235. {
  6236. mtrace();
  6237. int result = FAIL;
  6238. int connectorIdInt, durationInt;
  6239. char chargingRateUnitStr[4]={0};
  6240. char comfirmstr[20];
  6241. int confirmPeriods = 0;
  6242. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6243. json_object *GetCompositeSchedule;
  6244. GetCompositeSchedule = json_tokener_parse(payload);
  6245. if(!is_error(GetCompositeSchedule))
  6246. {
  6247. // Required data
  6248. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6249. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6250. // Optional data
  6251. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6252. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6253. }
  6254. json_object_put(GetCompositeSchedule);
  6255. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6256. if((connectorIdInt == 0) ||
  6257. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6258. {
  6259. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6260. struct StructChargingProfile tmpProfile[1];
  6261. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6262. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6263. {
  6264. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6265. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6266. }
  6267. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6268. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6269. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6270. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6271. {
  6272. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6273. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6274. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6275. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6276. {
  6277. confirmPeriods = idx;
  6278. break;
  6279. }
  6280. }
  6281. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6282. }
  6283. else
  6284. {
  6285. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6286. }
  6287. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6288. return result;
  6289. }
  6290. int handleGetConfigurationRequest(char *uuid, char *payload)
  6291. {
  6292. mtrace();
  6293. int result = FAIL;
  6294. int MaxKeySupported = 0;
  6295. int n_keys = 0;
  6296. char requestKey[43][50]={0};
  6297. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6298. json_object *GetConfiguration;
  6299. GetConfiguration = json_tokener_parse(payload);
  6300. if(!is_error(GetConfiguration))
  6301. {
  6302. // Optional data
  6303. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6304. {
  6305. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6306. {
  6307. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6308. n_keys = idx + 1;
  6309. }
  6310. }
  6311. }
  6312. json_object_put(GetConfiguration);
  6313. UnknownKeynum = 0;
  6314. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6315. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6316. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6317. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6318. if(n_keys != 0)
  6319. {
  6320. for(int i=0;i<n_keys;i++)
  6321. {
  6322. getKeyValue(requestKey[i]);
  6323. }
  6324. }
  6325. else
  6326. {
  6327. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6328. getKeyValue("");
  6329. }
  6330. processUnkownKey();
  6331. sendGetConfigurationConfirmation(uuid);
  6332. return result;
  6333. }
  6334. static char fnamePlusPath[100]={0};
  6335. static char fnamePWithNoPath[60]={0};
  6336. void checkUploadLog(void)
  6337. {
  6338. FILE *fp;
  6339. /* Open the command for reading. */
  6340. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6341. if (fp == NULL) {
  6342. printf("Failed to run command\n" );
  6343. exit(1);
  6344. }
  6345. int ftppathlen = 0;
  6346. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6347. int i = 0;
  6348. /* Read the output a line at a time - output it. */
  6349. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6350. if(i==0)
  6351. {
  6352. ftppathlen = strlen(fnamePlusPath);
  6353. printf("%s\n", fnamePlusPath);
  6354. fnamePlusPath[ftppathlen]='\0';
  6355. break;
  6356. }
  6357. i= i+1;
  6358. }
  6359. /* close */
  6360. pclose(fp);
  6361. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6362. {
  6363. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6364. {
  6365. fnamePlusPath[k]='\0';
  6366. }
  6367. }
  6368. i=1;
  6369. //char fname[60]={0};
  6370. while(i < ftppathlen)
  6371. {
  6372. int len=ftppathlen-i;
  6373. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6374. {
  6375. printf("compare '/' all right\n");
  6376. break;
  6377. }
  6378. i=i+1;
  6379. }
  6380. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6381. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6382. fnamePWithNoPath[i+1] = '\0';
  6383. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6384. {
  6385. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6386. {
  6387. fnamePWithNoPath[j]='\0';
  6388. }
  6389. }
  6390. FILE* fp1 = fopen(fnamePlusPath, "r");
  6391. if (fp1)
  6392. {
  6393. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6394. // file exists
  6395. fclose(fp1);
  6396. }
  6397. else
  6398. {
  6399. // file doesn't exist
  6400. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6401. }
  6402. }
  6403. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6404. {
  6405. mtrace();
  6406. int result = FAIL;
  6407. char cmdBuf[512];
  6408. char fName[258];
  6409. time_t CurrentTime;
  6410. struct tm *tm;
  6411. pthread_t th_Status;
  6412. CurrentTime = time(NULL);
  6413. tm = localtime(&CurrentTime);
  6414. sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  6415. sendGetDiagnosticsConfirmation(uuid, fName);
  6416. system("exec /root/logPackTools 'log' 6");
  6417. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6418. system(cmdBuf);
  6419. checkUploadLog();
  6420. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6421. return result;
  6422. }
  6423. void* GetDiagnosticsProcess(void* data)
  6424. {
  6425. pthread_detach(pthread_self());
  6426. mtrace();
  6427. int retriesInt=0, retryIntervalInt=0;
  6428. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6429. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6430. 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};
  6431. int port=0;
  6432. char sstr[260]={ 0 };
  6433. int c = 0;
  6434. char *loc;
  6435. int isSuccess = FALSE;
  6436. char ftpbuf[200]={0};
  6437. char * pch;
  6438. char str[300]={ 0 };
  6439. strcpy(str,(const char*)data);
  6440. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6441. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6442. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6443. //****************location*******************/
  6444. c = 0;
  6445. memset(sstr ,0, ARRAY_SIZE(sstr));
  6446. loc = strstr(str, "location");
  6447. while (loc[3+strlen("location")+c] != '\"')
  6448. {
  6449. sstr[c] = loc[3+strlen("location")+c];
  6450. c++;
  6451. }
  6452. sstr[c] = '\0';
  6453. strcpy(locationstr,sstr);
  6454. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6455. if(strcmp(locationstr,"")==0)
  6456. {
  6457. DEBUG_INFO("location is <Empty>!\n");
  6458. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6459. goto end;
  6460. }
  6461. //****************retries*******************/
  6462. c = 0;
  6463. loc = strstr(str, "retries");
  6464. if(loc == NULL)
  6465. {
  6466. retriesIsNULL = TRUE;
  6467. }
  6468. else
  6469. {
  6470. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6471. {
  6472. sstr[c] = loc[strlen("retries")+2+c];
  6473. c++;
  6474. }
  6475. sstr[c] = '\0';
  6476. retriesInt = atoi(sstr);
  6477. }
  6478. if(retriesIsNULL == TRUE)
  6479. {
  6480. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6481. }
  6482. //****************retryInterval*******************/
  6483. c = 0;
  6484. loc = strstr(str, "retryInterval");
  6485. if(loc == NULL)
  6486. {
  6487. retryIntervalIsNULL = TRUE;
  6488. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6489. }
  6490. else
  6491. {
  6492. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6493. {
  6494. sstr[c] = loc[strlen("retryInterval")+2+c];
  6495. c++;
  6496. }
  6497. sstr[c] = '\0';
  6498. retryIntervalInt = atoi(sstr);
  6499. }
  6500. //****************startTime*******************/
  6501. c = 0;
  6502. memset(sstr ,0, ARRAY_SIZE(sstr));
  6503. loc = strstr(str, "startTime");
  6504. if(loc == NULL)
  6505. {
  6506. startTimeIsNULL = TRUE;
  6507. }
  6508. else
  6509. {
  6510. while (loc[3+strlen("startTime")+c] != '\"')
  6511. {
  6512. sstr[c] = loc[3+strlen("startTime")+c];
  6513. c++;
  6514. }
  6515. sstr[c] = '\0';
  6516. strcpy(startTimestr,sstr);
  6517. }
  6518. //****************stopTime*******************/
  6519. c = 0;
  6520. memset(sstr ,0, ARRAY_SIZE(sstr));
  6521. loc = strstr(str, "stopTime");
  6522. if(loc == NULL)
  6523. {
  6524. stopTimeIsNULL = TRUE;
  6525. }
  6526. else
  6527. {
  6528. while (loc[3+strlen("stopTime")+c] != '\"')
  6529. {
  6530. sstr[c] = loc[3+strlen("stopTime")+c];
  6531. c++;
  6532. }
  6533. sstr[c] = '\0';
  6534. strcpy(stopTimestr,sstr);
  6535. }
  6536. memset(protocol, 0, ARRAY_SIZE(protocol));
  6537. memset(user, 0, ARRAY_SIZE(user) );
  6538. memset(password, 0, ARRAY_SIZE(password));
  6539. memset(host, 0, ARRAY_SIZE(host));
  6540. memset(path, 0, ARRAY_SIZE(path));
  6541. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6542. memset(host1, 0, ARRAY_SIZE(host1));
  6543. memset(path1, 0, ARRAY_SIZE(path1));
  6544. /*location: ftp://user:password@host:port/path*/
  6545. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6546. if((access(fnamePlusPath,F_OK))!=-1)
  6547. {
  6548. DEBUG_INFO("fnamePlusPath exist.\n");
  6549. }
  6550. else
  6551. {
  6552. DEBUG_INFO("fnamePlusPath not exist!\n");
  6553. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6554. goto end;
  6555. }
  6556. pch=strchr(locationstr,'@');
  6557. if(pch==NULL)
  6558. {
  6559. sscanf(locationstr,
  6560. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6561. protocol, host, &port, path);
  6562. strcpy(user,"anonymous");
  6563. strcpy(password,"");
  6564. }
  6565. else
  6566. {
  6567. //DEBUG_INFO("pch=%s\n", pch);
  6568. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6569. protocol, user, password, host, &port, path);
  6570. }
  6571. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6572. {
  6573. DEBUG_INFO("protocol is not ftp/http ! \n");
  6574. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6575. goto end;
  6576. }
  6577. if(strncmp(locationstr,"http", 4) == 0)
  6578. {
  6579. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6580. sprintf(ftppath,"/%s", path);
  6581. do{
  6582. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6583. sleep(retryIntervalInt);
  6584. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6585. if(!isSuccess)
  6586. {
  6587. DEBUG_INFO("Diagnostics fail.\n");
  6588. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6589. }
  6590. else
  6591. {
  6592. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6593. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6594. }
  6595. }
  6596. else
  6597. {
  6598. sscanf(host,"%[^/]%s",host1, path1);
  6599. sprintf(ftppath,"%s", path1);
  6600. int ftppathlen=strlen(ftppath);
  6601. int i=1;
  6602. char filenametemp[50];
  6603. while(i < ftppathlen)
  6604. {
  6605. int len=ftppathlen-i;
  6606. if(ftppath[len]== 47) // '/' ascll code: 47
  6607. {
  6608. DEBUG_INFO("find '/' all right\n");
  6609. break;
  6610. }
  6611. i=i+1;
  6612. }
  6613. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6614. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6615. filenametemp[i+1] = 0;
  6616. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6617. if(port == 0)
  6618. port = 21;
  6619. do{
  6620. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6621. sleep(retryIntervalInt);
  6622. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6623. if(!isSuccess)
  6624. {
  6625. DEBUG_INFO("Diagnostics fail.\n");
  6626. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6627. }
  6628. else
  6629. {
  6630. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6631. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6632. }
  6633. }
  6634. end:
  6635. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6636. pthread_exit(NULL);
  6637. }
  6638. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6639. {
  6640. mtrace();
  6641. int result = FAIL;
  6642. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6643. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6644. {
  6645. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6646. localversion = -1;
  6647. }
  6648. else
  6649. {
  6650. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6651. OCPP_getListVerion();
  6652. }
  6653. //from db.OCPP_getListVerion
  6654. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6655. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6656. sendGetLocalListVersionConfirmation(uuid,"");
  6657. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6658. return result;
  6659. }
  6660. int handleRemoteStartRequest(char *uuid, char *payload)
  6661. {
  6662. mtrace();
  6663. int result = FAIL;
  6664. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6665. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6666. int tempIndex = 0;
  6667. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6668. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6669. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6670. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6671. int chargingSchedulePeriodCount = 0;
  6672. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6673. int c = 0;
  6674. char *loc;
  6675. char comfirmstr[20]={0};
  6676. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6677. if(server_pending == TRUE)
  6678. {
  6679. return 0;
  6680. }
  6681. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6682. strcpy(sstrtemp, stringtrimspace(payload));
  6683. //**********connectorId****************/
  6684. c = 0;
  6685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6686. loc = strstr(sstrtemp, "connectorId");
  6687. if(loc == NULL)
  6688. {
  6689. connectorIdIsNULL = TRUE;
  6690. }
  6691. else
  6692. {
  6693. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6694. {
  6695. sstr[c] = loc[strlen("connectorId")+2+c];
  6696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6697. c++;
  6698. }
  6699. sstr[c] = '\0';
  6700. connectorIdInt = atoi(sstr);
  6701. }
  6702. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6703. {
  6704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6705. goto end;
  6706. }
  6707. //****************idTag*******************/
  6708. c = 0;
  6709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6710. loc = strstr(sstrtemp, "idTag");
  6711. while (loc[3+strlen("idTag")+c] != '\"')
  6712. {
  6713. sstr[c] = loc[3+strlen("idTag")+c];
  6714. c++;
  6715. }
  6716. sstr[c] = '\0';
  6717. strcpy(idTagstr,sstr);
  6718. //****************chargingProfile*******************/
  6719. c = 0;
  6720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6721. loc = strstr(sstrtemp, "chargingProfile");
  6722. if(loc == NULL)
  6723. {
  6724. chargingProfileIsNULL = TRUE;
  6725. }
  6726. else
  6727. {
  6728. //****************chargingProfileId*******************/
  6729. c=0;
  6730. loc = strstr(sstrtemp, "chargingProfileId");
  6731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6732. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6733. {
  6734. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6735. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6736. c++;
  6737. }
  6738. sstr[c] = '\0';
  6739. chargingProfileIdInt = atoi(sstr);
  6740. //****************transactionId*******************/
  6741. loc = strstr(sstrtemp, "transactionId");
  6742. if(loc == NULL)
  6743. {
  6744. transactionIdIsNULL = TRUE;
  6745. }
  6746. else
  6747. {
  6748. c=0;
  6749. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6750. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6751. {
  6752. sstr[c] = loc[strlen("transactionId")+2+c];
  6753. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6754. c++;
  6755. }
  6756. sstr[c] = '\0';
  6757. transactionIdInt = atoi(sstr);
  6758. }
  6759. //****************stackLevel*******************/
  6760. c=0;
  6761. loc = strstr(sstrtemp, "stackLevel");
  6762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6763. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6764. {
  6765. sstr[c] = loc[strlen("stackLevel")+2+c];
  6766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6767. c++;
  6768. }
  6769. sstr[c] = '\0';
  6770. stackLevelInt = atoi(sstr);
  6771. //****************chargingProfilePurpose*******************/
  6772. c = 0;
  6773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6774. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6775. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6776. {
  6777. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6778. c++;
  6779. }
  6780. sstr[c] = '\0';
  6781. strcpy(chargingProfilePurposestr,sstr);
  6782. //****************chargingProfileKind*******************/
  6783. c = 0;
  6784. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6785. loc = strstr(sstrtemp, "chargingProfileKind");
  6786. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6787. {
  6788. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6789. c++;
  6790. }
  6791. sstr[c] = '\0';
  6792. strcpy(chargingProfileKindstr,sstr);
  6793. //****************recurrencyKind*******************/
  6794. loc = strstr(sstrtemp, "recurrencyKind");
  6795. if(loc == NULL)
  6796. {
  6797. recurrencyKindIsNULL = TRUE;
  6798. }
  6799. else
  6800. {
  6801. c = 0;
  6802. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6803. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6804. {
  6805. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6806. c++;
  6807. }
  6808. sstr[c] = '\0';
  6809. strcpy(recurrencyKindstr,sstr);
  6810. }
  6811. //****************validFrom*******************/
  6812. loc = strstr(sstrtemp, "validFrom");
  6813. if(loc == NULL)
  6814. {
  6815. validFromIsNULL = TRUE;
  6816. }
  6817. else
  6818. {
  6819. c = 0;
  6820. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6821. while (loc[3+strlen("validFrom")+c] != '\"')
  6822. {
  6823. sstr[c] = loc[3+strlen("validFrom")+c];
  6824. c++;
  6825. }
  6826. sstr[c] = '\0';
  6827. strcpy(validFromstr,sstr);
  6828. }
  6829. //****************validTo*******************/
  6830. loc = strstr(sstrtemp, "validTo");
  6831. if(loc == NULL)
  6832. {
  6833. validToIsNULL = TRUE;
  6834. }
  6835. else
  6836. {
  6837. c = 0;
  6838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6839. while (loc[3+strlen("validTo")+c] != '\"')
  6840. {
  6841. sstr[c] = loc[3+strlen("validTo")+c];
  6842. c++;
  6843. }
  6844. sstr[c] = '\0';
  6845. strcpy(validTostr,sstr);
  6846. }
  6847. //****************chargingSchedule*******************/
  6848. loc = strstr(sstrtemp, "chargingSchedule");
  6849. if(loc != NULL)
  6850. {
  6851. //****************duration*******************/
  6852. loc = strstr(sstrtemp, "duration");
  6853. if(loc == NULL)
  6854. {
  6855. durationIsNULL = TRUE;
  6856. }
  6857. else
  6858. {
  6859. c=0;
  6860. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6861. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6862. {
  6863. sstr[c] = loc[strlen("duration")+2+c];
  6864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6865. c++;
  6866. }
  6867. sstr[c] = '\0';
  6868. durationInt = atoi(sstr);
  6869. }
  6870. //****************startSchedule******************/
  6871. loc = strstr(sstrtemp, "startSchedule");
  6872. if(loc == NULL)
  6873. {
  6874. startScheduleIsNULL = TRUE;
  6875. }
  6876. else
  6877. {
  6878. c = 0;
  6879. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6880. while (loc[3+strlen("startSchedule")+c] != '\"')
  6881. {
  6882. sstr[c] = loc[3+strlen("startSchedule")+c];
  6883. c++;
  6884. }
  6885. sstr[c] = '\0';
  6886. strcpy(startSchedulestr,sstr);
  6887. }
  6888. //****************chargingRateUnit*******************/
  6889. c = 0;
  6890. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6891. loc = strstr(sstrtemp, "chargingRateUnit");
  6892. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6893. {
  6894. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6895. c++;
  6896. }
  6897. sstr[c] = '\0';
  6898. strcpy(chargingRateUnitstr,sstr);
  6899. //****************minChargingRate*******************/
  6900. loc = strstr(sstrtemp, "minChargingRate");
  6901. if(loc == NULL)
  6902. {
  6903. minChargingRateIsNULL = TRUE;
  6904. }
  6905. else
  6906. {
  6907. c=0;
  6908. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6909. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6910. {
  6911. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6912. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6913. c++;
  6914. }
  6915. sstr[c] = '\0';
  6916. minChargingRateflaot = atof(sstr);
  6917. }
  6918. //****************chargingSchedulePeriod count*******************/
  6919. int what_len = strlen("startPeriod");
  6920. char *where = sstrtemp;
  6921. while ((where = strstr(where, "startPeriod"))) {
  6922. where += what_len;
  6923. chargingSchedulePeriodCount++;
  6924. }
  6925. where = sstrtemp;
  6926. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6927. {
  6928. //****************startPeriod*******************/
  6929. c=0;
  6930. loc = strstr(where, "startPeriod");
  6931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6932. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6933. {
  6934. sstr[c] = loc[strlen("startPeriod")+2+c];
  6935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6936. c++;
  6937. }
  6938. sstr[c] = '\0';
  6939. startPeriodInt[periodNums] = atoi(sstr);
  6940. //****************limit*******************/
  6941. c=0;
  6942. loc = strstr(where, "limit");
  6943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6944. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6945. {
  6946. sstr[c] = loc[strlen("limit")+2+c];
  6947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6948. c++;
  6949. }
  6950. sstr[c] = '\0';
  6951. limitflaot[periodNums] = atof(sstr);
  6952. //****************numberPhases*******************/
  6953. loc = strstr(where, "numberPhases");
  6954. if(loc == NULL)
  6955. {
  6956. numberPhasesIsNULL = TRUE;
  6957. }
  6958. else
  6959. {
  6960. c=0;
  6961. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6962. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6963. {
  6964. sstr[c] = loc[strlen("numberPhases")+2+c];
  6965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6966. c++;
  6967. }
  6968. sstr[c] = '\0';
  6969. numberPhasesInt[periodNums] = atoi(sstr);
  6970. }
  6971. where = loc;
  6972. } // END FOR chargingSchedulePeriodCount
  6973. }// END IF chargingSchedule
  6974. } // END chargingProfile
  6975. /*
  6976. enum _SYSTEM_STATUS
  6977. {
  6978. S_BOOTING = 0,
  6979. S_IDLE, = 1
  6980. S_AUTHORIZING, =2
  6981. S_REASSIGN_CHECK, =3
  6982. S_REASSIGN, =4
  6983. S_PRECHARGE, =5
  6984. S_PREPARING_FOR_EV, =6
  6985. S_PREPARING_FOR_EVSE, =7
  6986. S_CHARGING, =8
  6987. S_TERMINATING, =9
  6988. S_COMPLETE, =10
  6989. S_ALARM, =11
  6990. S_FAULT =12
  6991. }
  6992. */
  6993. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6994. {
  6995. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6996. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6997. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6998. //check Transaction active
  6999. if(gunType[connectorIdInt -1] == 'J')
  7000. {
  7001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7002. {
  7003. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7004. }
  7005. else
  7006. {
  7007. tempIndex = connectorIdInt -1;
  7008. }
  7009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7012. {
  7013. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7014. {
  7015. //Reserved
  7016. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7017. }
  7018. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7019. {
  7020. //Reserved
  7021. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7022. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7023. goto end;
  7024. }
  7025. else
  7026. {
  7027. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7028. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7029. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7030. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7031. {
  7032. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7033. goto end;
  7034. }
  7035. }//END FOR ELSE
  7036. }
  7037. }// END FOR CHAdeMO_QUANTITY
  7038. }
  7039. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7040. {
  7041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7042. {
  7043. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7044. }
  7045. else
  7046. {
  7047. tempIndex = connectorIdInt -1;
  7048. }
  7049. for (int index = 0; index < CCS_QUANTITY; index++)
  7050. {
  7051. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7052. {
  7053. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7054. {
  7055. //Reserved
  7056. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7057. }
  7058. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7059. {
  7060. //Reserved
  7061. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7062. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7063. goto end;
  7064. }
  7065. else
  7066. {
  7067. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7068. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7069. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7070. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7071. {
  7072. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7073. goto end;
  7074. }
  7075. }// END FOR ELSE
  7076. }
  7077. }// END FOR CCS_QUANTITY
  7078. }
  7079. else if(gunType[connectorIdInt -1] == 'G')
  7080. {
  7081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7082. {
  7083. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7084. }
  7085. else
  7086. {
  7087. tempIndex = connectorIdInt -1;
  7088. }
  7089. for (int index = 0; index < GB_QUANTITY; index++)
  7090. {
  7091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7092. {
  7093. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7094. {
  7095. //Reserved
  7096. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7097. }
  7098. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7099. {
  7100. //Reserved
  7101. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7103. goto end;
  7104. }
  7105. else
  7106. {
  7107. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7108. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7109. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7110. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7111. {
  7112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7113. goto end;
  7114. }
  7115. }// END FOR ELSE
  7116. }
  7117. } // END FOR GB_QUANTITY
  7118. }
  7119. else
  7120. {
  7121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7122. {
  7123. tempIndex = 2;
  7124. }
  7125. else
  7126. {
  7127. tempIndex = connectorIdInt -1;
  7128. }
  7129. for (int index = 0; index < AC_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7132. {
  7133. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7134. {
  7135. //Reserved
  7136. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7137. }
  7138. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7139. {
  7140. //Reserved
  7141. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7142. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7143. goto end;
  7144. }
  7145. else
  7146. {
  7147. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7148. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7149. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7150. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7151. {
  7152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7153. goto end;
  7154. }
  7155. }//END FOR ELSE
  7156. }
  7157. }// END FOR AC_QUANTITY
  7158. }
  7159. if(chargingProfileIsNULL == FALSE)
  7160. {
  7161. //ChargingProfile
  7162. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7163. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7164. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7165. if(recurrencyKindIsNULL == FALSE) //OPTION
  7166. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7167. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7168. if(transactionIdIsNULL == FALSE) // OPTION
  7169. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7170. if(validFromIsNULL == FALSE) // OPTION
  7171. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7172. if(validToIsNULL == FALSE) //OPTION
  7173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7174. //ChargingSchedule
  7175. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7176. if(durationIsNULL == FALSE) //OPTION
  7177. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7178. if(minChargingRateIsNULL == FALSE) //OPTION
  7179. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7180. if(startScheduleIsNULL == FALSE) //OPTION
  7181. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7182. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7183. {
  7184. //ChargingSchedulePeriod
  7185. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7186. if(numberPhasesIsNULL == FALSE)
  7187. {
  7188. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7189. }
  7190. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7191. }
  7192. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7193. {
  7194. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7196. //memset idTag
  7197. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7198. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7199. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7200. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7201. }
  7202. else
  7203. {
  7204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7205. }
  7206. }
  7207. else
  7208. {
  7209. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7210. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7211. //memset idTag
  7212. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7213. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7214. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7215. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7216. }
  7217. }
  7218. else
  7219. {
  7220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7221. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7222. }
  7223. end:
  7224. if(connectorIdIsNULL == FALSE)
  7225. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7226. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7227. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7228. //OCPP send RemoteStartConfirmation by first.
  7229. sendRemoteStartConfirmation(uuid, comfirmstr);
  7230. return result;
  7231. }
  7232. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7233. {
  7234. mtrace();
  7235. int result = FAIL;
  7236. int match = FALSE;
  7237. int GunNO = 0;
  7238. int tempIndex = 0;
  7239. int transactionIdInt=0;
  7240. int transactionIdIsNULL= FALSE;
  7241. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7242. int c = 0;
  7243. char *loc;
  7244. char comfirmstr[20];
  7245. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7246. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7247. if(server_pending == TRUE)
  7248. {
  7249. return 0;
  7250. }
  7251. strcpy(sstrtemp, stringtrimspace(payload));
  7252. c=0;
  7253. loc = strstr(sstrtemp, "transactionId");
  7254. if(loc == NULL)
  7255. {
  7256. transactionIdIsNULL= TRUE;
  7257. }
  7258. else
  7259. {
  7260. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7261. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7262. {
  7263. sstr[c] = loc[strlen("transactionId")+2+c];
  7264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7265. c++;
  7266. }
  7267. sstr[c] = '\0';
  7268. transactionIdInt = atoi(sstr);
  7269. }
  7270. if(transactionIdIsNULL == FALSE)
  7271. {
  7272. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7273. {
  7274. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7275. {
  7276. //check Transaction active
  7277. if(gunType[gun_index] == 'J')
  7278. {
  7279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7280. {
  7281. tempIndex = ((gun_index==2) ? 1: 0);
  7282. }
  7283. else
  7284. {
  7285. tempIndex = gun_index;
  7286. }
  7287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7288. {
  7289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7290. {
  7291. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7292. {
  7293. match = TRUE;
  7294. GunNO = gun_index;
  7295. }
  7296. }
  7297. }// END FOR CHAdeMO_QUANTITY
  7298. }
  7299. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7300. {
  7301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7302. {
  7303. tempIndex = ((gun_index==2) ? 1: 0);
  7304. }
  7305. else
  7306. {
  7307. tempIndex = gun_index;
  7308. }
  7309. for (int index = 0; index < CCS_QUANTITY; index++)
  7310. {
  7311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7312. {
  7313. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7314. {
  7315. match = TRUE;
  7316. GunNO = gun_index;
  7317. }
  7318. }
  7319. }// END FOR CCS_QUANTITY
  7320. }
  7321. else if(gunType[gun_index] == 'G')
  7322. {
  7323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7324. {
  7325. tempIndex = ((gun_index==2) ? 1: 0);
  7326. }
  7327. else
  7328. {
  7329. tempIndex = gun_index;
  7330. }
  7331. for (int index = 0; index < GB_QUANTITY; index++)
  7332. {
  7333. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7334. {
  7335. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7336. {
  7337. match = TRUE;
  7338. GunNO = gun_index;
  7339. }
  7340. }
  7341. }// END FOR GB_QUANTITY
  7342. }
  7343. else
  7344. {
  7345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7346. {
  7347. tempIndex = 2;
  7348. }
  7349. else
  7350. {
  7351. tempIndex = gun_index;
  7352. }
  7353. for (int index = 0; index < AC_QUANTITY; index++)
  7354. {
  7355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7356. {
  7357. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7358. {
  7359. match = TRUE;
  7360. GunNO = gun_index;
  7361. }
  7362. }
  7363. }// END FOR CHAdeMO_QUANTITY
  7364. } // END FOR AC ELSE
  7365. }// CHECK IF ResponseTransactionId == transactionIdInt
  7366. }//END FOR
  7367. if( match == TRUE)
  7368. {
  7369. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7371. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7372. }
  7373. else
  7374. {
  7375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7376. }
  7377. }
  7378. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7379. return result;
  7380. }
  7381. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7382. {
  7383. mtrace();
  7384. int result = FAIL;
  7385. int connectorIdInt=0, reservationIdInt=0;
  7386. int tempIndex = 0;
  7387. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7388. char comfirmstr[20]={0};
  7389. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7390. int c = 0;
  7391. char *loc;
  7392. //char *ptr;
  7393. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7394. strcpy(sstrtemp, stringtrimspace(payload));
  7395. //***(1)connectorId ****/
  7396. c=0;
  7397. loc = strstr(sstrtemp, "connectorId");
  7398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7399. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7400. {
  7401. sstr[c] = loc[strlen("connectorId")+2+c];
  7402. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7403. c++;
  7404. }
  7405. sstr[c] = '\0';
  7406. connectorIdInt = atoi(sstr);
  7407. //***(2)expiryDate ****/
  7408. loc = strstr(sstrtemp, "expiryDate");
  7409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7410. c = 0;
  7411. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7412. {
  7413. sstr[c] = loc[3+strlen("expiryDate")+c];
  7414. c++;
  7415. }
  7416. sstr[c] = '\0';
  7417. strcpy(expiryDatestr, sstr);
  7418. //***(3)idTag ****/
  7419. loc = strstr(sstrtemp, "idTag");
  7420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7421. c = 0;
  7422. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7423. {
  7424. sstr[c] = loc[3+strlen("idTag")+c];
  7425. c++;
  7426. }
  7427. sstr[c] = '\0';
  7428. strcpy(idTagstr, sstr);
  7429. //***(4)parentIdTag ****/
  7430. loc = strstr(sstrtemp, "parentIdTag");
  7431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7432. c = 0;
  7433. if(loc == NULL)
  7434. {
  7435. strcpy(parentIdTagstr, "");
  7436. }
  7437. else
  7438. {
  7439. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7440. {
  7441. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(parentIdTagstr, sstr);
  7446. }
  7447. //***(5)reservationId ****/
  7448. c=0;
  7449. loc = strstr(sstrtemp, "reservationId");
  7450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7451. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7452. {
  7453. sstr[c] = loc[strlen("reservationId")+2+c];
  7454. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7455. c++;
  7456. }
  7457. sstr[c] = '\0';
  7458. reservationIdInt = atoi(sstr);
  7459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7460. /*
  7461. enum SYSTEM_STATUS
  7462. {
  7463. SYS_MODE_BOOTING = 0,
  7464. SYS_MODE_IDLE = 1,
  7465. SYS_MODE_AUTHORIZING = 2,
  7466. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7467. SYS_MODE_REASSIGN = 4,
  7468. SYS_MODE_PREPARING = 5,
  7469. SYS_MODE_PREPARE_FOR_EV = 6,
  7470. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7471. SYS_MODE_CHARGING = 8,
  7472. SYS_MODE_TERMINATING = 9,
  7473. SYS_MODE_COMPLETE = 10,
  7474. SYS_MODE_ALARM = 11,
  7475. SYS_MODE_FAULT = 12,
  7476. SYS_MODE_RESERVATION = 13,
  7477. SYS_MODE_BOOKING = 14,
  7478. SYS_MODE_MAINTAIN = 15,
  7479. SYS_MODE_DEBUG = 16,
  7480. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7481. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7482. SYS_MODE_UPDATE = 19
  7483. };
  7484. */
  7485. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7486. {
  7487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7488. goto end;
  7489. }
  7490. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7491. {
  7492. //check Transaction active
  7493. if(gunType[connectorIdInt -1] == 'J')
  7494. {
  7495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7496. {
  7497. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7498. }
  7499. else
  7500. {
  7501. tempIndex = connectorIdInt -1;
  7502. }
  7503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7504. {
  7505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7506. {
  7507. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7508. {
  7509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7510. {
  7511. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7512. {
  7513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7515. }
  7516. 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'))
  7517. {
  7518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7519. }
  7520. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7521. {
  7522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7523. }
  7524. else
  7525. {
  7526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7527. }
  7528. }
  7529. 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
  7530. {
  7531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7532. }
  7533. }
  7534. else
  7535. {
  7536. //replace reservation
  7537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7539. }
  7540. }
  7541. } // END FOR CHAdeMO_QUANTITY
  7542. }
  7543. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7544. {
  7545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7546. {
  7547. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7548. }
  7549. else
  7550. {
  7551. tempIndex = connectorIdInt -1;
  7552. }
  7553. for (int index = 0; index < CCS_QUANTITY; index++)
  7554. {
  7555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7556. {
  7557. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7558. {
  7559. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7560. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7561. {
  7562. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7563. {
  7564. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7566. }
  7567. 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'))
  7568. {
  7569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7570. }
  7571. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7572. {
  7573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7574. }
  7575. else
  7576. {
  7577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7578. }
  7579. }
  7580. 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
  7581. {
  7582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7583. }
  7584. }
  7585. else
  7586. {
  7587. //replace reservation
  7588. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7590. }
  7591. }
  7592. } // END FOR CCS_QUANTITY
  7593. }
  7594. else if(gunType[connectorIdInt -1] == 'G')
  7595. {
  7596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7597. {
  7598. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7599. }
  7600. else
  7601. {
  7602. tempIndex = connectorIdInt -1;
  7603. }
  7604. for (int index = 0; index < GB_QUANTITY; index++)
  7605. {
  7606. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7607. {
  7608. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7609. {
  7610. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7611. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7612. {
  7613. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7614. {
  7615. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7617. }
  7618. 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'))
  7619. {
  7620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7621. }
  7622. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7623. {
  7624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7625. }
  7626. else
  7627. {
  7628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7629. }
  7630. }
  7631. 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
  7632. {
  7633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7634. }
  7635. }
  7636. else
  7637. {
  7638. //replace reservation
  7639. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7641. }
  7642. }
  7643. }// END FOR GB_QUANTITY
  7644. }
  7645. else
  7646. {
  7647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7648. {
  7649. tempIndex = 2;
  7650. }
  7651. else
  7652. {
  7653. tempIndex = (connectorIdInt -1);
  7654. }
  7655. for (int index = 0; index < AC_QUANTITY; index++)
  7656. {
  7657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7658. {
  7659. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7660. {
  7661. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7662. {
  7663. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7664. {
  7665. 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))
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7668. }
  7669. else
  7670. {
  7671. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7673. }
  7674. }
  7675. 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'))
  7676. {
  7677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7678. }
  7679. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7680. {
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7682. }
  7683. else
  7684. {
  7685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7686. }
  7687. }
  7688. 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
  7689. {
  7690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7691. }
  7692. }
  7693. else
  7694. {
  7695. //replace reservation
  7696. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7698. }
  7699. }
  7700. } // END FOR AC_QUANTITY
  7701. }
  7702. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7703. }
  7704. else if(connectorIdInt == 0)
  7705. {
  7706. //check Transaction active
  7707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7708. {
  7709. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7710. {
  7711. 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'))
  7712. {
  7713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7714. goto end;
  7715. }
  7716. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7719. goto end;
  7720. }
  7721. 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
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7724. goto end;
  7725. }
  7726. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7729. goto end;
  7730. }
  7731. }
  7732. }// END FOR CHAdeMO_QUANTITY
  7733. for (int index = 0; index < CCS_QUANTITY; index++)
  7734. {
  7735. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7736. {
  7737. 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'))
  7738. {
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7740. goto end;
  7741. }
  7742. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7745. goto end;
  7746. }
  7747. 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
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7750. goto end;
  7751. }
  7752. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7753. {
  7754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7755. goto end;
  7756. }
  7757. }
  7758. } // END FOR CCS_QUANTITY
  7759. for (int index = 0; index < GB_QUANTITY; index++)
  7760. {
  7761. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7762. {
  7763. 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'))
  7764. {
  7765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7766. goto end;
  7767. }
  7768. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7769. {
  7770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7771. goto end;
  7772. }
  7773. 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
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7776. goto end;
  7777. }
  7778. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7781. goto end;
  7782. }
  7783. }
  7784. } // END FOR GB_QUANTITY
  7785. for (int index = 0; index < AC_QUANTITY; index++)
  7786. {
  7787. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7788. {
  7789. 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'))
  7790. {
  7791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7792. goto end;
  7793. }
  7794. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7795. {
  7796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7797. goto end;
  7798. }
  7799. 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
  7800. {
  7801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7802. goto end;
  7803. }
  7804. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7805. {
  7806. 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))
  7807. {
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7809. goto end;
  7810. }
  7811. }
  7812. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7813. {
  7814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7815. goto end;
  7816. }
  7817. }
  7818. }// END FOR AC_QUANTITY
  7819. //The connectorId is 0
  7820. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7822. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7823. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7824. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7825. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7826. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7827. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7828. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7829. result = TRUE;
  7830. return result;
  7831. }
  7832. else
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7835. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7836. }
  7837. if(strcmp(comfirmstr,"Accepted") == 0)
  7838. {
  7839. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7840. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7841. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7842. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7843. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7844. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7845. result = TRUE;
  7846. return result;
  7847. }
  7848. end:
  7849. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7850. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7851. return result;
  7852. }
  7853. int handleResetRequest(char *uuid, char *payload)
  7854. {
  7855. mtrace();
  7856. int result = FAIL;
  7857. char sstr[10]={0},sstrtemp[30]={ 0 };
  7858. char typestr[10]={0};
  7859. char comfirmstr[20]={0};
  7860. int c = 0;
  7861. char *loc;
  7862. DEBUG_INFO("handleResetRequest...\n");
  7863. strcpy(sstrtemp, stringtrimspace(payload));
  7864. loc = strstr(sstrtemp, "type");
  7865. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7866. c = 0;
  7867. while (loc[3+strlen("type")+c] != '\"')
  7868. {
  7869. sstr[c] = loc[3+strlen("type")+c];
  7870. c++;
  7871. }
  7872. sstr[c] = '\0';
  7873. strcpy(typestr,sstr);
  7874. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7875. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7876. {
  7877. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7878. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7879. result = TRUE;
  7880. return result;
  7881. }
  7882. else
  7883. {
  7884. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7885. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7886. goto errorend;
  7887. }
  7888. errorend:
  7889. sendResetConfirmation(uuid, comfirmstr);
  7890. return result;
  7891. }
  7892. int handleSendLocalListRequest(char *uuid, char *payload)
  7893. {
  7894. mtrace();
  7895. int result = FAIL;
  7896. int listVersionInt;
  7897. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7898. char listsearch[]="listVersion";
  7899. char updateTypesearch[]="updateType";
  7900. char localAuthorizationListsearch[]="localAuthorizationList";
  7901. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7902. char CardList[500][160]={0};
  7903. char updateTypestr[15]={0};
  7904. char idTagstr[20]={0};
  7905. char parentIdTag[20]={0};
  7906. char expiryDate[30]={0};
  7907. char idTagstatus[16]={0};
  7908. int c = 0;
  7909. int i = 0;
  7910. char *delim1 = "}";
  7911. char * pch;
  7912. char *loc;
  7913. //char *ptr;
  7914. char comfirmstr[20];
  7915. //int n_localAuthorizations = 0;
  7916. int checkState_Faulted = FALSE;
  7917. DEBUG_INFO("handleSendLocalListRequest...\n");
  7918. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7919. {
  7920. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7921. goto end;
  7922. }
  7923. //check Charge Point state
  7924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7925. {
  7926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7927. {
  7928. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7929. }
  7930. }
  7931. for (int index = 0; index < CCS_QUANTITY; index++)
  7932. {
  7933. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7934. {
  7935. checkState_Faulted = TRUE; //OCPP Status
  7936. }
  7937. }
  7938. for (int index = 0; index < GB_QUANTITY; index++)
  7939. {
  7940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7941. {
  7942. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7943. }
  7944. }
  7945. //check Charge Point state
  7946. for (int index = 0; index < AC_QUANTITY; index++)
  7947. {
  7948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7949. {
  7950. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7951. }
  7952. }
  7953. if(checkState_Faulted == TRUE)
  7954. {
  7955. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7956. goto end;
  7957. }
  7958. //Filter payload space
  7959. strcpy(sstrtemp, stringtrimspace(payload));
  7960. //listVersion
  7961. c = 0;
  7962. loc = strstr(sstrtemp, listsearch);
  7963. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7964. {
  7965. sstr[c] = loc[strlen("listVersion")+2+c];
  7966. c++;
  7967. }
  7968. sstr[c] = '\0';
  7969. listVersionInt = atoi(sstr);
  7970. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7971. //updateType
  7972. loc = strstr(sstrtemp, updateTypesearch);
  7973. c = 0;
  7974. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7975. {
  7976. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7977. c++;
  7978. }
  7979. sstr[c] = '\0';
  7980. strcpy(updateTypestr, sstr);
  7981. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7982. //localAuthorizationList
  7983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7984. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7985. if(loc != NULL) // localAuthorizationList is not NULL
  7986. {
  7987. //Check UpdateType
  7988. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7989. {
  7990. //Local list full update
  7991. printf("Local list full update.\n");
  7992. OCPP_getListVerion();
  7993. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7994. {
  7995. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7996. goto end;
  7997. }
  7998. OCPP_cleanLocalList();
  7999. }
  8000. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8001. {
  8002. //Local list different update
  8003. printf("Local list different update.\n");
  8004. OCPP_getListVerion();
  8005. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8006. {
  8007. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8008. goto end;
  8009. }
  8010. }
  8011. else
  8012. {
  8013. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8014. goto end;
  8015. }
  8016. c = 0;
  8017. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8018. {
  8019. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8020. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8021. c++;
  8022. }
  8023. sstr[c] = '\0';
  8024. //DEBUG_INFO("sstr=%s\n", sstr);
  8025. //parsing strings to words
  8026. i = 0;
  8027. pch = strtok(sstr,delim1);
  8028. while (pch != NULL)
  8029. {
  8030. strcpy(CardList[i], pch);
  8031. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8032. pch = strtok (NULL, delim1);
  8033. i = i + 1;
  8034. }
  8035. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8036. //local Authorizations List Numbers
  8037. //n_localAuthorizations = i;
  8038. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8039. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8040. c= 0;
  8041. while(c < i) // i is CardList Number
  8042. {
  8043. //Search "IdToken"
  8044. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8045. loc = strstr(CardList[c], "idTag");
  8046. int j = 0;
  8047. while (loc[3+strlen("idTag")+j] != '\"')
  8048. {
  8049. sstr[j] = loc[3+strlen("idTag")+j];
  8050. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8051. j++;
  8052. }
  8053. sstr[j] = '\0';
  8054. strcpy(idTagstr, sstr);
  8055. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8056. //Search "expiryDate"
  8057. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8058. loc = strstr(CardList[c], "expiryDate");
  8059. j = 0;
  8060. if(loc != NULL)
  8061. {
  8062. while (loc[3+strlen("expiryDate")+j] != '\"')
  8063. {
  8064. sstr[j] = loc[3+strlen("expiryDate")+j];
  8065. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8066. j++;
  8067. }
  8068. sstr[j] = '\0';
  8069. strcpy(expiryDate, sstr);
  8070. }
  8071. else
  8072. {
  8073. strcpy(expiryDate, "");
  8074. }
  8075. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8076. //Search "parentIdTag"
  8077. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8078. loc = strstr(CardList[c], "parentIdTag");
  8079. j = 0;
  8080. if(loc != NULL)
  8081. {
  8082. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8083. {
  8084. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8085. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8086. j++;
  8087. }
  8088. sstr[j] = '\0';
  8089. strcpy(parentIdTag, sstr);
  8090. }
  8091. else
  8092. {
  8093. strcpy(parentIdTag, "");
  8094. }
  8095. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8096. //Search "status"
  8097. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8098. loc = strstr(CardList[c], "status");
  8099. j = 0;
  8100. while (loc[3+strlen("status")+j] != '\"')
  8101. {
  8102. sstr[j] = loc[3+strlen("status")+j];
  8103. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8104. j++;
  8105. }
  8106. sstr[j] = '\0';
  8107. strcpy(idTagstatus, sstr);
  8108. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8109. OCPP_getIdTag(idTagstr);
  8110. //OCPP_getIdTag("test"); For Test
  8111. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8112. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8113. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8114. {
  8115. //Local list full update
  8116. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8117. // update list
  8118. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8119. //DEBUG_INFO("Local list full update. 1\n");
  8120. //OCPP_get_TableAuthlocalAllData();
  8121. //DEBUG_INFO("Local list full update. 2\n");
  8122. }
  8123. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8124. {
  8125. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8126. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8127. }
  8128. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8129. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8130. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8131. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8132. c++;
  8133. }
  8134. }
  8135. else
  8136. {
  8137. //Check UpdateType
  8138. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8139. {
  8140. //Local list full update
  8141. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8142. OCPP_cleanLocalList();
  8143. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8144. goto end;
  8145. }
  8146. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8147. {
  8148. //Local list different update
  8149. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8151. goto end;
  8152. }
  8153. }
  8154. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8155. end:
  8156. sendSendLocalListConfirmation(uuid, comfirmstr);
  8157. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8158. return result;
  8159. }
  8160. #define MAX 200
  8161. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8166. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8167. char chargingProfilePurposeStr[30]={0};
  8168. char chargingProfileKindStr[16]={0};
  8169. char recurrencyKindStr[10]={0};
  8170. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8171. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8172. int chargingSchedulePeriodCount = 0;
  8173. //int updateflag = FALSE;
  8174. char comfirmstr[20]={0};
  8175. int meet= FALSE;
  8176. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8177. int c = 0;
  8178. char *loc;
  8179. FILE *fptr1;//, *fptr2;
  8180. //int lno=0;//, linectr = 0;
  8181. //int modifyflag = FALSE;
  8182. char filename[MAX]={0};
  8183. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8184. //int resultRename=0;
  8185. char rmFileCmd[50]={0};
  8186. char tempchargingProfilePurposeStr[30]={0};
  8187. char word[1600]={0};
  8188. int n_chargingProfile = 0;
  8189. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  8190. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8191. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8192. //Filter string space
  8193. strcpy(sstrtemp, stringtrimspace(payload));
  8194. //*********************connectorId***************************/
  8195. loc = strstr(sstrtemp, "connectorId");
  8196. c = 0;
  8197. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8198. while (loc[strlen("connectorId")+2+c] != ',')
  8199. {
  8200. sstr[c] = loc[strlen("connectorId")+2+c];
  8201. c++;
  8202. }
  8203. sstr[c] = '\0';
  8204. connectorIdInt = atoi(sstr);
  8205. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8206. {
  8207. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8208. }
  8209. else
  8210. {
  8211. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8212. }
  8213. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8214. //*********************chargingProfileId***************************/
  8215. loc = strstr(sstrtemp, "chargingProfileId");
  8216. c = 0;
  8217. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8218. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8219. {
  8220. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8221. c++;
  8222. }
  8223. sstr[c] = '\0';
  8224. chargingProfileIdInt = atoi(sstr);
  8225. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8226. {
  8227. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8228. }
  8229. else
  8230. {
  8231. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8232. }
  8233. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8234. //*********************transactionId***************************/
  8235. loc = strstr(sstrtemp, "transactionId");
  8236. if(loc != NULL)
  8237. {
  8238. c = 0;
  8239. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8240. while (loc[strlen("transactionId")+2+c] != ',')
  8241. {
  8242. sstr[c] = loc[strlen("transactionId")+2+c];
  8243. c++;
  8244. }
  8245. sstr[c] = '\0';
  8246. transactionIdInt = atoi(sstr);
  8247. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8248. {
  8249. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8250. }
  8251. else
  8252. {
  8253. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8254. }
  8255. }
  8256. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8257. //*********************stackLevel***************************/
  8258. loc = strstr(sstrtemp, "stackLevel");
  8259. c = 0;
  8260. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8261. while (loc[strlen("stackLevel")+2+c] != ',')
  8262. {
  8263. sstr[c] = loc[strlen("stackLevel")+2+c];
  8264. c++;
  8265. }
  8266. sstr[c] = '\0';
  8267. stackLevelInt = atoi(sstr);
  8268. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8269. {
  8270. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8271. }
  8272. else
  8273. {
  8274. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8275. }
  8276. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8277. //*********************chargingProfilePurpose***************************/
  8278. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8279. c = 0;
  8280. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8281. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8282. {
  8283. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8285. c++;
  8286. }
  8287. sstr[c] = '\0';
  8288. strcpy(chargingProfilePurposeStr,sstr);
  8289. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8290. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8291. {
  8292. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8293. }
  8294. else
  8295. {
  8296. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8297. }
  8298. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8299. //*********************chargingProfileKind***************************/
  8300. loc = strstr(sstrtemp, "chargingProfileKind");
  8301. c = 0;
  8302. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8303. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8304. {
  8305. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8307. c++;
  8308. }
  8309. sstr[c] = '\0';
  8310. strcpy(chargingProfileKindStr,sstr);
  8311. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8312. {
  8313. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8314. }
  8315. else
  8316. {
  8317. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8318. }
  8319. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8320. //*********************recurrencyKind***************************/
  8321. loc = strstr(sstrtemp, "recurrencyKind");
  8322. if(loc != NULL)
  8323. {
  8324. c = 0;
  8325. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8326. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8327. {
  8328. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8329. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8330. c++;
  8331. }
  8332. sstr[c] = '\0';
  8333. strcpy(recurrencyKindStr,sstr);
  8334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8335. {
  8336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8337. }
  8338. else
  8339. {
  8340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8341. }
  8342. }
  8343. else
  8344. {
  8345. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8346. {
  8347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8348. }
  8349. else
  8350. {
  8351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8352. }
  8353. }
  8354. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8355. //*********************validFrom***************************/
  8356. loc = strstr(sstrtemp, "validFrom");
  8357. if(loc != NULL)
  8358. {
  8359. c = 0;
  8360. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8361. while (loc[3+strlen("validFrom")+c] != '\"')
  8362. {
  8363. sstr[c] = loc[3+strlen("validFrom")+c];
  8364. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8365. c++;
  8366. }
  8367. sstr[c] = '\0';
  8368. strcpy(validFromStr,sstr);
  8369. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8370. {
  8371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8372. }
  8373. else
  8374. {
  8375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8376. }
  8377. }
  8378. else
  8379. {
  8380. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8381. {
  8382. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8383. }
  8384. else
  8385. {
  8386. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8387. }
  8388. }
  8389. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8390. //*********************validTo***************************/
  8391. loc = strstr(sstrtemp, "validTo");
  8392. if(loc != NULL)
  8393. {
  8394. c = 0;
  8395. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8396. while (loc[3+strlen("validTo")+c] != '\"')
  8397. {
  8398. sstr[c] = loc[3+strlen("validTo")+c];
  8399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8400. c++;
  8401. }
  8402. sstr[c] = '\0';
  8403. strcpy(validToStr,sstr);
  8404. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8405. {
  8406. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8407. }
  8408. else
  8409. {
  8410. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8411. }
  8412. }
  8413. else
  8414. {
  8415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8416. {
  8417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8418. }
  8419. else
  8420. {
  8421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8422. }
  8423. }
  8424. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8425. //*********************duration***************************/
  8426. loc = strstr(sstrtemp, "duration");
  8427. if(loc != NULL)
  8428. {
  8429. c = 0;
  8430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8431. while (loc[strlen("duration")+2+c] != ',')
  8432. {
  8433. sstr[c] = loc[strlen("duration")+2+c];
  8434. c++;
  8435. }
  8436. sstr[c] = '\0';
  8437. durationInt = atoi(sstr);
  8438. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8439. {
  8440. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8441. }
  8442. else
  8443. {
  8444. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8445. }
  8446. }
  8447. else
  8448. {
  8449. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8450. {
  8451. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8452. }
  8453. else
  8454. {
  8455. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8456. }
  8457. }
  8458. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8459. //*********************startSchedule***************************/
  8460. loc = strstr(sstrtemp, "startSchedule");
  8461. if(loc != NULL)
  8462. {
  8463. c = 0;
  8464. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8465. while (loc[3+strlen("startSchedule")+c] != '\"')
  8466. {
  8467. sstr[c] = loc[3+strlen("startSchedule")+c];
  8468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8469. c++;
  8470. }
  8471. sstr[c] = '\0';
  8472. strcpy(startScheduleStr,sstr);
  8473. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8474. {
  8475. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8476. }
  8477. else
  8478. {
  8479. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8480. }
  8481. }
  8482. else
  8483. {
  8484. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8485. {
  8486. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8487. }
  8488. else
  8489. {
  8490. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8491. }
  8492. }
  8493. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8494. //*********************chargingRateUnit***************************/
  8495. loc = strstr(sstrtemp, "chargingRateUnit");
  8496. if(loc != NULL)
  8497. {
  8498. c = 0;
  8499. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8500. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8501. {
  8502. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8503. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8504. c++;
  8505. }
  8506. sstr[c] = '\0';
  8507. strcpy(chargingRateUnitStr,sstr);
  8508. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8509. {
  8510. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8511. }
  8512. else
  8513. {
  8514. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8515. }
  8516. }
  8517. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8518. //****************chargingSchedulePeriod count start*******************/
  8519. int what_len = strlen("startPeriod");
  8520. char tempChargingProfile[1600]={0};
  8521. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8522. char *where = tempChargingProfile;
  8523. if (what_len)
  8524. {
  8525. while ((where = strstr(where, "startPeriod"))) {
  8526. where += what_len;
  8527. chargingSchedulePeriodCount++;
  8528. }
  8529. }
  8530. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8531. {
  8532. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8533. goto end;
  8534. }
  8535. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8536. //where = payload;
  8537. int templength = 0;
  8538. //int searchstart = 0;
  8539. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8540. {
  8541. //****************startPeriod*******************/
  8542. c=0;
  8543. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8544. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8545. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8546. {
  8547. sstr[c] = loc[strlen("startPeriod")+2+c];
  8548. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8549. c++;
  8550. }
  8551. sstr[c] = '\0';
  8552. startPeriodInt[periodNums] = atoi(sstr);
  8553. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8554. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8555. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8556. {
  8557. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8558. }
  8559. else
  8560. {
  8561. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8562. }
  8563. templength = strlen("startPeriod")+2+c;
  8564. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8565. //****************limit*******************/
  8566. c=0;
  8567. loc = strstr(tempChargingProfile + templength, "limit");
  8568. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8569. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8570. {
  8571. sstr[c] = loc[strlen("limit")+2+c];
  8572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8573. c++;
  8574. }
  8575. sstr[c] = '\0';
  8576. limitflaot[periodNums] = atof(sstr);
  8577. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8578. {
  8579. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8580. }
  8581. else
  8582. {
  8583. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8584. }
  8585. templength = templength + strlen("limit")+2+c;
  8586. //****************numberPhases*******************/
  8587. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8588. if(loc != NULL)
  8589. {
  8590. c=0;
  8591. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8592. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8593. {
  8594. sstr[c] = loc[strlen("numberPhases")+2+c];
  8595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8596. c++;
  8597. }
  8598. sstr[c] = '\0';
  8599. numberPhasesInt[periodNums] = atoi(sstr);
  8600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8601. {
  8602. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8603. }
  8604. else
  8605. {
  8606. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8607. }
  8608. templength = templength + strlen("numberPhases")+2+c;
  8609. }
  8610. //where = loc;
  8611. }
  8612. //****************chargingSchedulePeriod count end*******************/
  8613. //*********************minChargingRate***************************/
  8614. loc = strstr(sstrtemp, "minChargingRate");
  8615. if(loc != NULL)
  8616. {
  8617. c = 0;
  8618. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8619. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8620. {
  8621. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8622. c++;
  8623. }
  8624. sstr[c] = '\0';
  8625. minChargingRateFloat = atof(sstr);
  8626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8627. {
  8628. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8629. }
  8630. else
  8631. {
  8632. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8633. }
  8634. }
  8635. else
  8636. {
  8637. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8638. {
  8639. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8640. }
  8641. else
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8644. }
  8645. }
  8646. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8647. {
  8648. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8649. if(connectorIdInt != 0)
  8650. {
  8651. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8652. goto end;
  8653. }
  8654. strcpy(filename, ChargePointMaxProfile_JSON );
  8655. fptr1 = fopen(filename, "r");
  8656. if (!fptr1)
  8657. {
  8658. //file not exist
  8659. DEBUG_INFO("Unable to open the input file!!\n");
  8660. fptr1 = fopen(filename, "w+");
  8661. }
  8662. else
  8663. {
  8664. //Check Charging Profile Count
  8665. while(fscanf(fptr1, "%s", word) != EOF)
  8666. {
  8667. //DEBUG_INFO("word=%s\n",word);
  8668. if(strstr(word, "chargingProfileId")!= NULL)
  8669. {
  8670. //DEBUG_INFO("test chargingProfileId \n");
  8671. n_chargingProfile = n_chargingProfile + 1;
  8672. //DEBUG_INFO("chargingProfileId Found\n");
  8673. }
  8674. }
  8675. }
  8676. fclose(fptr1);
  8677. }
  8678. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8679. {
  8680. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8681. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8682. {
  8683. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8684. goto end;
  8685. }
  8686. memset(filename, 0, ARRAY_SIZE(filename));
  8687. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8688. fptr1 = fopen(filename, "r");
  8689. if (!fptr1)
  8690. {
  8691. //file not exist
  8692. //DEBUG_INFO("Unable to open the input file!!\n");
  8693. fptr1 = fopen(filename, "w+");
  8694. }
  8695. else
  8696. {
  8697. //Check Charging Profile Count
  8698. while(fscanf(fptr1, "%s", word) != EOF)
  8699. {
  8700. //DEBUG_INFO("word=%s\n",word);
  8701. if(strstr(word, "chargingProfileId")!= NULL)
  8702. {
  8703. //DEBUG_INFO("test chargingProfileId \n");
  8704. n_chargingProfile = n_chargingProfile + 1;
  8705. //DEBUG_INFO("chargingProfileId Found\n");
  8706. }
  8707. }
  8708. }
  8709. fclose(fptr1);
  8710. }
  8711. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8712. {
  8713. //printf("set chargingProfile 1-4\n");
  8714. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8715. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8716. if(connectorIdInt == 0)
  8717. {
  8718. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8719. goto end;
  8720. }
  8721. int tempIndex = 0;
  8722. //check Transaction active
  8723. if(gunType[connectorIdInt -1] == 'J')
  8724. {
  8725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8726. {
  8727. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8728. }
  8729. else
  8730. {
  8731. tempIndex = connectorIdInt -1;
  8732. }
  8733. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8734. {
  8735. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8736. {
  8737. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8738. {
  8739. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8740. {
  8741. meet = TRUE;
  8742. break;
  8743. }
  8744. }
  8745. }
  8746. }
  8747. }
  8748. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8749. {
  8750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8751. {
  8752. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8753. }
  8754. else
  8755. {
  8756. tempIndex = connectorIdInt -1;
  8757. }
  8758. for (int index = 0; index < CCS_QUANTITY; index++)
  8759. {
  8760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8761. {
  8762. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8763. {
  8764. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8765. {
  8766. meet = TRUE;
  8767. break;
  8768. }
  8769. }
  8770. }
  8771. }
  8772. }
  8773. else if(gunType[connectorIdInt -1] == 'G')
  8774. {
  8775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8776. {
  8777. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8778. }
  8779. else
  8780. {
  8781. tempIndex = connectorIdInt -1;
  8782. }
  8783. for (int index = 0; index < GB_QUANTITY; index++)
  8784. {
  8785. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8786. {
  8787. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8788. {
  8789. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8790. {
  8791. meet = TRUE;
  8792. break;
  8793. }
  8794. }
  8795. }
  8796. }
  8797. }
  8798. else
  8799. {
  8800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8801. {
  8802. tempIndex = 2;
  8803. }
  8804. else
  8805. {
  8806. tempIndex = (connectorIdInt -1);
  8807. }
  8808. for (int index = 0; index < AC_QUANTITY; index++)
  8809. {
  8810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8811. {
  8812. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8813. {
  8814. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8815. {
  8816. meet = TRUE;
  8817. break;
  8818. }
  8819. }
  8820. }
  8821. }
  8822. }
  8823. //check Transaction active
  8824. if(meet == FALSE)
  8825. {
  8826. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8827. goto end;
  8828. }
  8829. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8830. {
  8831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8832. goto end;
  8833. }
  8834. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8835. fptr1 = fopen(filename, "r");
  8836. if (!fptr1)
  8837. {
  8838. //file not exist
  8839. DEBUG_INFO("Unable to open the input file!!\n");
  8840. fptr1 = fopen(filename, "w+");
  8841. }
  8842. else
  8843. {
  8844. //Check Charging Profile Count
  8845. while(fscanf(fptr1, "%s", word) != EOF)
  8846. {
  8847. //DEBUG_INFO("word=%s\n",word);
  8848. if(strstr(word, "chargingProfileId")!= NULL)
  8849. {
  8850. //DEBUG_INFO("test chargingProfileId \n");
  8851. n_chargingProfile = n_chargingProfile + 1;
  8852. //DEBUG_INFO("chargingProfileId Found\n");
  8853. }
  8854. }
  8855. }
  8856. fclose(fptr1);
  8857. }
  8858. // Check ChargeProfileMaxStackLevel
  8859. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8860. {
  8861. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8862. goto end;
  8863. }
  8864. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8865. {
  8866. int i = 0;
  8867. char fnametemp[200]={0};
  8868. n_chargingProfile = 0;
  8869. //Check ChargePointMaxProfile.json exit
  8870. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8871. {
  8872. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8873. //Check Charging Profile Count
  8874. while(fscanf(fptr1, "%s", word) != EOF)
  8875. {
  8876. //DEBUG_INFO("word=%s\n",word);
  8877. if(strstr(word, "chargingProfileId")!= NULL)
  8878. {
  8879. //DEBUG_INFO("test chargingProfileId \n");
  8880. n_chargingProfile = n_chargingProfile + 1;
  8881. i = i + 1;
  8882. //DEBUG_INFO("chargingProfileId Found\n");
  8883. }
  8884. memset(word, 0, ARRAY_SIZE(word));
  8885. }
  8886. fclose(fptr1);
  8887. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8888. }
  8889. //Check TxDefaultProfile_0.json exit
  8890. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8891. {
  8892. i = 0;
  8893. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8894. //Check Charging Profile Count
  8895. while(fscanf(fptr1, "%s", word) != EOF)
  8896. {
  8897. //DEBUG_INFO("word=%s\n",word);
  8898. if(strstr(word, "chargingProfileId")!= NULL)
  8899. {
  8900. //DEBUG_INFO("test chargingProfileId \n");
  8901. n_chargingProfile = n_chargingProfile + 1;
  8902. i = i + 1;
  8903. //DEBUG_INFO("chargingProfileId Found\n");
  8904. }
  8905. memset(word, 0, ARRAY_SIZE(word));
  8906. }
  8907. fclose(fptr1);
  8908. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8909. }
  8910. //Check TxDefaultProfile_%d.json
  8911. for(int j=1; j <= gunTotalNumber; j++)
  8912. {
  8913. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8914. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8915. if((access(fnametemp,F_OK))!=-1)
  8916. {
  8917. i = 0;
  8918. fptr1 = fopen(fnametemp, "r");
  8919. //Check Charging Profile Count
  8920. while(fscanf(fptr1, "%s", word) != EOF)
  8921. {
  8922. //DEBUG_INFO("word=%s\n",word);
  8923. if(strstr(word, "chargingProfileId")!= NULL)
  8924. {
  8925. //DEBUG_INFO("test chargingProfileId \n");
  8926. n_chargingProfile = n_chargingProfile + 1;
  8927. i = i + 1;
  8928. //DEBUG_INFO("chargingProfileId Found\n");
  8929. }
  8930. memset(word, 0, ARRAY_SIZE(word));
  8931. }
  8932. fclose(fptr1);
  8933. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8934. }
  8935. }
  8936. //Check TxProfile_%d.json
  8937. for(int j=1; j <= gunTotalNumber; j++)
  8938. {
  8939. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8940. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8941. if((access(fnametemp,F_OK))!=-1)
  8942. {
  8943. i = 0;
  8944. fptr1 = fopen(fnametemp, "r");
  8945. //Check Charging Profile Count
  8946. while(fscanf(fptr1, "%s", word) != EOF)
  8947. {
  8948. //DEBUG_INFO("word=%s\n",word);
  8949. if(strstr(word, "chargingProfileId")!= NULL)
  8950. {
  8951. //DEBUG_INFO("test chargingProfileId \n");
  8952. n_chargingProfile = n_chargingProfile + 1;
  8953. i = i + 1;
  8954. //DEBUG_INFO("chargingProfileId Found\n");
  8955. }
  8956. memset(word, 0, ARRAY_SIZE(word));
  8957. }
  8958. fclose(fptr1);
  8959. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8960. }
  8961. }
  8962. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8963. {
  8964. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8965. goto end;
  8966. }
  8967. }
  8968. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8969. //**********************************Write to File********************************************************/
  8970. FILE *infile;
  8971. FILE *outfile;
  8972. // open file for writing
  8973. infile = fopen (filename, "r");
  8974. outfile = fopen (tempfile, "w");
  8975. int d =0;
  8976. d = fgetc(infile);
  8977. //DEBUG_INFO("d:%d\n",d);
  8978. rewind(infile);
  8979. //*璉 瘚 辣蝏     1嚗   0 */
  8980. if(d == EOF)
  8981. {
  8982. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8983. fprintf(outfile,"%s\n",payload);
  8984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8985. fclose(infile);
  8986. fclose(outfile);
  8987. sprintf(rmFileCmd,"rm -f %s",filename);
  8988. system(rmFileCmd);
  8989. rename(tempfile, filename);
  8990. sleep(1);
  8991. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8992. //system(rmFileCmd);
  8993. }
  8994. else
  8995. {
  8996. char buf[1000]={0};
  8997. int ChargingProfileAdded = FALSE;
  8998. while (fgets(buf, sizeof(buf), infile) != NULL)
  8999. {
  9000. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9001. //*************************tempconnectorIdInt*********************************/
  9002. loc = strstr(buf, "connectorId");
  9003. c = 0;
  9004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9005. while (loc[strlen("connectorId")+2+c] != ',')
  9006. {
  9007. sstr[c] = loc[strlen("connectorId")+2+c];
  9008. c++;
  9009. }
  9010. sstr[c] = '\0';
  9011. tempconnectorIdInt = atoi(sstr);
  9012. //*************************tempchargingProfileIdInt*********************************/
  9013. loc = strstr(buf, "chargingProfileId");
  9014. c = 0;
  9015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9016. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9017. {
  9018. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9019. c++;
  9020. }
  9021. sstr[c] = '\0';
  9022. tempchargingProfileIdInt = atoi(sstr);
  9023. //*************************tempstackLevelInt*********************************/
  9024. loc = strstr(buf, "stackLevel");
  9025. c = 0;
  9026. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9027. while (loc[strlen("stackLevel")+2+c] != ',')
  9028. {
  9029. sstr[c] = loc[strlen("stackLevel")+2+c];
  9030. c++;
  9031. }
  9032. sstr[c] = '\0';
  9033. tempstackLevelInt = atoi(sstr);
  9034. //*************************tempchargingProfilePurposeStr*********************************/
  9035. loc = strstr(payload, "chargingProfilePurpose");
  9036. c = 0;
  9037. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9038. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9039. {
  9040. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9041. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9042. c++;
  9043. }
  9044. sstr[c] = '\0';
  9045. strcpy(tempchargingProfilePurposeStr,sstr);
  9046. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9047. {
  9048. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9049. {
  9050. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9051. if(ChargingProfileAdded == FALSE)
  9052. {
  9053. fprintf(outfile,"%s\n",payload);
  9054. ChargingProfileAdded = TRUE;
  9055. }
  9056. }
  9057. else
  9058. {
  9059. if(tempstackLevelInt < stackLevelInt)
  9060. {
  9061. if(ChargingProfileAdded == FALSE)
  9062. {
  9063. fprintf(outfile,"%s\n",payload);
  9064. ChargingProfileAdded = TRUE;
  9065. fprintf(outfile,"%s\n",buf);
  9066. }
  9067. else
  9068. {
  9069. fprintf(outfile,"%s\n",buf);
  9070. }
  9071. }
  9072. else
  9073. {
  9074. if(ChargingProfileAdded == FALSE)
  9075. {
  9076. fprintf(outfile,"%s\n",buf);
  9077. fprintf(outfile,"%s\n",payload);
  9078. ChargingProfileAdded = TRUE;
  9079. }
  9080. else
  9081. {
  9082. fprintf(outfile,"%s\n",buf);
  9083. }
  9084. }
  9085. }
  9086. }
  9087. else
  9088. {
  9089. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9090. {
  9091. if(ChargingProfileAdded == FALSE)
  9092. {
  9093. fprintf(outfile,"%s\n",payload);
  9094. ChargingProfileAdded = TRUE;
  9095. fprintf(outfile,"%s\n",buf);
  9096. }
  9097. else
  9098. {
  9099. fprintf(outfile,"%s\n",buf);
  9100. }
  9101. }
  9102. else if(tempstackLevelInt < stackLevelInt)
  9103. {
  9104. if(ChargingProfileAdded == FALSE)
  9105. {
  9106. fprintf(outfile,"%s\n",payload);
  9107. ChargingProfileAdded = TRUE;
  9108. fprintf(outfile,"%s\n",buf);
  9109. }
  9110. else
  9111. {
  9112. fprintf(outfile,"%s\n",buf);
  9113. }
  9114. }
  9115. else
  9116. {
  9117. if(ChargingProfileAdded == FALSE)
  9118. {
  9119. fprintf(outfile,"%s\n",buf);
  9120. fprintf(outfile,"%s\n",payload);
  9121. ChargingProfileAdded = TRUE;
  9122. }
  9123. else
  9124. {
  9125. fprintf(outfile,"%s\n",buf);
  9126. }
  9127. }
  9128. }
  9129. } // end of while loop
  9130. fclose(infile);
  9131. fclose(outfile);
  9132. sprintf(rmFileCmd,"rm -f %s",filename);
  9133. system(rmFileCmd);
  9134. rename(tempfile, filename);
  9135. sleep(1);
  9136. result = TRUE;
  9137. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9138. }
  9139. end:
  9140. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9141. return result;
  9142. return result;
  9143. }
  9144. int handleTriggerMessageRequest(char *uuid, char *payload)
  9145. {
  9146. mtrace();
  9147. int result = FAIL;
  9148. int connectorIdIsNULL = FALSE;
  9149. int connectorIdInt =0;
  9150. char sstr[40]={0},sstrtemp[100]={ 0 };
  9151. char requestedMessagestr[40]={0};
  9152. char comfirmstr[20]={0};
  9153. int c = 0;
  9154. char *loc;
  9155. DEBUG_INFO("handleTriggerMessageRequest\n");
  9156. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9157. strcpy(sstrtemp, stringtrimspace(payload));
  9158. c = 0;
  9159. loc = strstr(sstrtemp, "requestedMessage");
  9160. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9161. {
  9162. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9163. c++;
  9164. }
  9165. sstr[c] = '\0';
  9166. strcpy(requestedMessagestr, sstr);
  9167. c = 0;
  9168. loc = strstr(sstrtemp, "connectorId");
  9169. if(loc == NULL)
  9170. {
  9171. connectorIdIsNULL = TRUE;
  9172. }
  9173. else
  9174. {
  9175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9176. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9177. {
  9178. sstr[c] = loc[strlen("connectorId")+2+c];
  9179. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9180. c++;
  9181. }
  9182. sstr[c] = '\0';
  9183. connectorIdInt = atoi(sstr);
  9184. }
  9185. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9186. {
  9187. //connectorIdInt = json_object_get_int(connectorId);
  9188. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9189. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9190. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9191. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9192. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9193. }
  9194. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9195. {
  9196. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9197. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9198. return TRUE;
  9199. }
  9200. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9201. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9202. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9203. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9204. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9205. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9206. {
  9207. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9208. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9209. return TRUE;
  9210. }
  9211. else
  9212. {
  9213. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9214. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9215. }
  9216. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9217. {
  9218. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9219. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9220. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9221. {
  9222. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9223. }
  9224. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9225. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9226. }
  9227. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9228. {
  9229. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9230. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9231. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9232. }
  9233. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9234. {
  9235. sendBootNotificationRequest();
  9236. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9237. }
  9238. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9239. {
  9240. sendHeartbeatRequest(connectorIdInt);
  9241. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9242. }
  9243. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9244. {
  9245. if(connectorIdIsNULL == FALSE)
  9246. {
  9247. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9248. {
  9249. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9250. sendMeterValuesRequest(connectorIdInt -1);
  9251. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9252. }
  9253. }
  9254. else
  9255. {
  9256. for(int idx=0;idx< gunTotalNumber;idx++)
  9257. {
  9258. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9259. sendMeterValuesRequest(idx);
  9260. }
  9261. }
  9262. }
  9263. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9264. {
  9265. if(connectorIdIsNULL == FALSE)
  9266. {
  9267. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9268. {
  9269. sendStatusNotificationRequest(connectorIdInt -1);
  9270. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9271. }
  9272. }
  9273. else
  9274. {
  9275. for(int idx=0;idx< gunTotalNumber;idx++)
  9276. sendStatusNotificationRequest(idx);
  9277. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9278. }
  9279. }
  9280. return result;
  9281. }
  9282. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9283. {
  9284. mtrace();
  9285. int result = FAIL;
  9286. char sstr[6]={0},sstrtemp[50]={ 0 };
  9287. int connectorIdInt =0;
  9288. char comfirmstr[20]={0};
  9289. int c = 0;
  9290. int tempIndex = 0;
  9291. char *loc;
  9292. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9293. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9294. strcpy(sstrtemp, stringtrimspace(payload));
  9295. c = 0;
  9296. loc = strstr(sstrtemp, "connectorId");
  9297. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9298. while (loc[strlen("connectorId")+2+c] != '}')
  9299. {
  9300. sstr[c] = loc[strlen("connectorId")+2+c];
  9301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9302. c++;
  9303. }
  9304. sstr[c] = '\0';
  9305. connectorIdInt = atoi(sstr);
  9306. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9307. if(gunTotalNumber == 0)
  9308. {
  9309. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9310. goto end;
  9311. }
  9312. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9313. {
  9314. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9315. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9316. goto end;
  9317. }
  9318. else
  9319. {
  9320. //check Transaction active
  9321. if(gunType[connectorIdInt-1] == 'J')
  9322. {
  9323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9324. {
  9325. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9326. }
  9327. else
  9328. {
  9329. tempIndex = connectorIdInt -1;
  9330. }
  9331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9332. {
  9333. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9334. {
  9335. //stop Transaction
  9336. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9337. }
  9338. }
  9339. }
  9340. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9341. {
  9342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9343. {
  9344. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9345. }
  9346. else
  9347. {
  9348. tempIndex = connectorIdInt -1;
  9349. }
  9350. for (int index = 0; index < CCS_QUANTITY; index++)
  9351. {
  9352. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9353. {
  9354. //stop Transaction
  9355. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9356. }
  9357. }
  9358. }
  9359. else if(gunType[connectorIdInt-1] == 'G')
  9360. {
  9361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9362. {
  9363. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9364. }
  9365. else
  9366. {
  9367. tempIndex = connectorIdInt -1;
  9368. }
  9369. for (int index = 0; index < GB_QUANTITY; index++)
  9370. {
  9371. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9372. {
  9373. //stop Transaction
  9374. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9375. }
  9376. }
  9377. }
  9378. else
  9379. {
  9380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9381. {
  9382. tempIndex = 2;
  9383. }
  9384. else
  9385. {
  9386. tempIndex = connectorIdInt-1;
  9387. }
  9388. for (int index = 0; index < AC_QUANTITY; index++)
  9389. {
  9390. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9391. {
  9392. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9393. }
  9394. }
  9395. }
  9396. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9397. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9398. result = TRUE;
  9399. return result;
  9400. }
  9401. end:
  9402. //json_object_put(obj); --- remove temporally
  9403. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9404. return result;
  9405. }
  9406. static char UpdateFirmwarepayloadData[300]={0};
  9407. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9408. {
  9409. mtrace();
  9410. int result = FAIL;
  9411. pthread_t t;
  9412. sendUpdateFirmwareConfirmation(uuid);
  9413. memset(UpdateFirmwarepayloadData, 0, 300);
  9414. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9415. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9416. ////pthread_join(t, NULL); //
  9417. //pthread_detach(t);
  9418. //sendUpdateFirmwareConfirmation(uuid);
  9419. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9420. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9421. return result;
  9422. }
  9423. void *UpdateFirmwareProcess(void *data)
  9424. {
  9425. pthread_detach(pthread_self());
  9426. mtrace();
  9427. int retriesInt =0, retryIntervalInt=0;
  9428. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9429. int port=0;
  9430. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9431. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9432. //char comfirmstr[20];
  9433. int isSuccess = 0;
  9434. char ftpbuf[200];
  9435. char temp[100];
  9436. char * pch;
  9437. int retriesISNULL=FALSE;
  9438. int retryInterval=FALSE;
  9439. int c = 0;
  9440. //int i = 0;
  9441. char *loc;
  9442. char sstr[300]={ 0 };
  9443. char str[300]={ 0 };
  9444. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9445. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9446. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9447. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9448. //***************location **************/
  9449. loc = strstr(str, "location");
  9450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9451. c = 0;
  9452. while (loc[3+strlen("location")+c] != '\"')
  9453. {
  9454. sstr[c] = loc[3+strlen("location")+c];
  9455. c++;
  9456. }
  9457. sstr[c] = '\0';
  9458. strcpy(locationstr, sstr);
  9459. //***************retries**************/
  9460. c = 0;
  9461. loc = strstr(str, "retries");
  9462. if(loc == NULL)
  9463. {
  9464. retriesISNULL=TRUE;
  9465. }
  9466. else
  9467. {
  9468. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9469. while (loc[strlen("retries")+2+c] != ',')
  9470. {
  9471. sstr[c] = loc[strlen("retries")+2+c];
  9472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9473. c++;
  9474. }
  9475. sstr[c] = '\0';
  9476. }
  9477. if(retriesISNULL == FALSE)
  9478. {
  9479. retriesInt = atoi(sstr);
  9480. }
  9481. //***************retrieveDate **************/
  9482. loc = strstr(str, "retrieveDate");
  9483. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9484. c = 0;
  9485. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9486. {
  9487. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9488. c++;
  9489. }
  9490. sstr[c] = '\0';
  9491. strcpy(retrieveDatestr, sstr);
  9492. //***************retryInterval **************/
  9493. c = 0;
  9494. loc = strstr(str, "retryInterval");
  9495. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9496. if(loc == NULL)
  9497. {
  9498. retryInterval=TRUE;
  9499. }
  9500. else
  9501. {
  9502. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9503. {
  9504. sstr[c] = loc[strlen("retryInterval")+2+c];
  9505. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9506. c++;
  9507. }
  9508. sstr[c] = '\0';
  9509. }
  9510. if(retryInterval==FALSE)
  9511. {
  9512. retryIntervalInt = atoi(sstr);
  9513. }
  9514. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9515. memset(path, 0, ARRAY_SIZE(path));
  9516. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9517. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9518. if(strncmp(locationstr,"http", 4) == 0)
  9519. {
  9520. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9521. protocol, host, path);
  9522. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9523. // protocol, user, password, host, path);
  9524. sprintf(ftppath,"/%s", path);
  9525. //DEBUG_INFO("protocol =%s\n",protocol);
  9526. //DEBUG_INFO("host =%s\n",host);
  9527. //DEBUG_INFO("path =%s\n",path);
  9528. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9529. int ftppathlen=strlen(ftppath);
  9530. int i=1;
  9531. char filenametemp[50];
  9532. while(i < ftppathlen)
  9533. {
  9534. int len=ftppathlen-i;
  9535. if(ftppath[len]== 47) // '/' ascll code: 47
  9536. {
  9537. DEBUG_INFO("compare '/' all right\n");
  9538. break;
  9539. }
  9540. i=i+1;
  9541. }
  9542. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9543. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9544. filenametemp[i+1] = 0;
  9545. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9546. do{
  9547. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9548. sleep(retryIntervalInt);
  9549. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9550. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9551. if(!isSuccess)
  9552. {
  9553. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9554. }
  9555. else
  9556. {
  9557. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9558. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9559. //isUpdateRequest = TRUE;
  9560. }
  9561. }
  9562. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9563. {
  9564. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9565. memset(temp, 0, ARRAY_SIZE(temp));
  9566. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9567. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9568. int ftppathlen=strlen(ftpbuf);
  9569. int i=1;
  9570. char filenametemp[50];
  9571. while(i < ftppathlen)
  9572. {
  9573. int len=ftppathlen-i;
  9574. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9575. {
  9576. DEBUG_INFO(" compare '/' all right\n");
  9577. break;
  9578. }
  9579. i=i+1;
  9580. }
  9581. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9582. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9583. filenametemp[i+1] = 0;
  9584. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9585. pch=strchr(temp,'@');
  9586. if(pch==NULL)
  9587. {
  9588. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9589. protocol, host, &port, path);
  9590. strcpy(user,"anonymous");
  9591. strcpy(password,"");
  9592. }
  9593. else
  9594. {
  9595. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9596. protocol, user, password, host, &port, path);
  9597. }
  9598. sscanf(host,"%[^/]%s",host1, path1);
  9599. sprintf(ftppath,"%s", path1);
  9600. //DEBUG_INFO("protocol =%s\n",protocol);
  9601. //DEBUG_INFO("user =%s\n",user);
  9602. //DEBUG_INFO("password =%s\n",password);
  9603. //DEBUG_INFO("host1 =%s\n",host1);
  9604. //DEBUG_INFO("port =%d\n",port);
  9605. //DEBUG_INFO("path1 =%s\n",path1);
  9606. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9607. //ftpFile(host, user, password, port, ftppath, fname);
  9608. //download firmware pthred
  9609. if(port == 0)
  9610. {
  9611. port = 21;
  9612. }
  9613. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9614. do{
  9615. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9616. sleep(retryIntervalInt);
  9617. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9618. if(!isSuccess)
  9619. {
  9620. //BulldogUtil.sleepMs(interval*1000);
  9621. DEBUG_INFO("Update firmware request and download file fail.\n");
  9622. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9623. }
  9624. else
  9625. {
  9626. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9627. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9628. //isUpdateRequest = TRUE;
  9629. }
  9630. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9631. }
  9632. else
  9633. {
  9634. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9635. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9636. }
  9637. pthread_exit(NULL);
  9638. }
  9639. //==========================================
  9640. // Handle server response routine
  9641. //==========================================
  9642. void handleAuthorizeResponse(char *payload, int gun_index)
  9643. {
  9644. mtrace();
  9645. char expiryDatestr[30]={0};
  9646. char parentIdTagstr[20]={0};
  9647. char statusstr[20]={0};
  9648. char expiryDatestrtemp[30]={0};
  9649. char parentIdTagstrtemp[20]={0};
  9650. char IdTagstrtemp[20]={0};
  9651. char statusstrtemp[20]={0};
  9652. int expiryDateISNULL=FALSE;
  9653. int parentIdTagISNULL=FALSE;
  9654. char sstr[160]={0};
  9655. char* filename = AuthorizationCache_JSON;
  9656. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9657. char *loc;
  9658. int resultRename=0;
  9659. int responseIdTagInfoAsZero= 0;
  9660. char rmFileCmd[50]={0};
  9661. DEBUG_INFO("handleAuthorizeResponse...\n");
  9662. json_object *Authorize;
  9663. Authorize = json_tokener_parse(payload);
  9664. if(!is_error(Authorize))
  9665. {
  9666. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9667. {
  9668. // Required data
  9669. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9670. // Optional data
  9671. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9672. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9673. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9674. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9675. }
  9676. }
  9677. json_object_put(Authorize);
  9678. if(expiryDateISNULL == FALSE)
  9679. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9680. if(parentIdTagISNULL == FALSE)
  9681. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9682. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9683. //Update idTag information to authorization cache if supproted
  9684. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9685. {
  9686. if((access(filename,F_OK))!=-1)
  9687. {
  9688. printf("AuthorizationCache exist.\n");
  9689. }
  9690. else
  9691. {
  9692. printf("AuthorizationCache not exist\n");
  9693. FILE *log = fopen(filename, "w+");
  9694. if(log == NULL)
  9695. {
  9696. printf("log is NULL\n");
  9697. goto out;
  9698. }
  9699. else
  9700. {
  9701. fclose(log);
  9702. }
  9703. }
  9704. FILE *infile;
  9705. FILE *outfile;
  9706. // open file for writing
  9707. infile = fopen (filename, "r");
  9708. outfile = fopen (tempfile, "w");
  9709. int c;
  9710. c = fgetc(infile);
  9711. //DEBUG_INFO("c:%d\n",c);
  9712. rewind(infile);
  9713. if(c == EOF)
  9714. {
  9715. DEBUG_INFO("Orignal File is NULL\n");
  9716. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9717. {
  9718. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9719. }
  9720. else
  9721. {
  9722. strcpy(expiryDatestrtemp, "");
  9723. }
  9724. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9725. {
  9726. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9727. }
  9728. else
  9729. {
  9730. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9731. }
  9732. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9733. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9734. fclose(infile);
  9735. fclose(outfile);
  9736. sprintf(rmFileCmd,"rm -f %s",filename);
  9737. system(rmFileCmd);
  9738. resultRename = rename(tempfile, filename);
  9739. if(resultRename == 0)
  9740. {
  9741. printf("File renamed successfully");
  9742. }
  9743. else
  9744. {
  9745. printf("Error: unable to rename the file");
  9746. }
  9747. }
  9748. else
  9749. {
  9750. char buf[160]={0};
  9751. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9752. {
  9753. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9754. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9755. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9756. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9757. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9758. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9759. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9760. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9761. //------------------IdTag-----------------------
  9762. loc = strstr(buf, "idTag");
  9763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9764. c = 0;
  9765. while (loc[3+strlen("idTag")+c] != '\"')
  9766. {
  9767. sstr[c] = loc[3+strlen("idTag")+c];
  9768. c++;
  9769. }
  9770. sstr[c] = '\0';
  9771. strcpy(IdTagstrtemp,sstr);
  9772. //*********************expiryDate***************/
  9773. loc = strstr(buf, "expiryDate");
  9774. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9775. c = 0;
  9776. while (loc[3+strlen("expiryDate")+c] != '\"')
  9777. {
  9778. sstr[c] = loc[3+strlen("expiryDate")+c];
  9779. c++;
  9780. }
  9781. sstr[c] = '\0';
  9782. strcpy(expiryDatestr,sstr);
  9783. //*********************parentIdTag***************/
  9784. loc = strstr(buf, "parentIdTag");
  9785. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9786. c = 0;
  9787. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9788. {
  9789. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9790. c++;
  9791. }
  9792. sstr[c] = '\0';
  9793. strcpy(parentIdTagstr,sstr);
  9794. //*********************status***************/
  9795. loc = strstr(buf, "status");
  9796. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9797. c = 0;
  9798. while (loc[3+strlen("status")+c] != '\"')
  9799. {
  9800. sstr[c] = loc[3+strlen("status")+c];
  9801. c++;
  9802. }
  9803. sstr[c] = '\0';
  9804. strcpy(statusstr,sstr);
  9805. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9806. {
  9807. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9808. responseIdTagInfoAsZero = 1;
  9809. }
  9810. else
  9811. {
  9812. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9813. }
  9814. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9815. {
  9816. //modify item
  9817. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9818. {
  9819. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9820. }
  9821. else
  9822. {
  9823. strcpy(expiryDatestrtemp, "");
  9824. }
  9825. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9826. {
  9827. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9828. }
  9829. else
  9830. {
  9831. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9832. }
  9833. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9834. }
  9835. else
  9836. {
  9837. //wrie original item
  9838. strcpy(expiryDatestrtemp, expiryDatestr);
  9839. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9840. strcpy(statusstrtemp, statusstr);
  9841. }
  9842. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9843. }
  9844. fclose(infile);
  9845. fclose(outfile);
  9846. sprintf(rmFileCmd,"rm -f %s",filename);
  9847. system(rmFileCmd);
  9848. resultRename = rename(tempfile, filename);
  9849. if(resultRename == 0)
  9850. {
  9851. DEBUG_INFO("File renamed successfully");
  9852. }
  9853. else
  9854. {
  9855. DEBUG_INFO("Error: unable to rename the file");
  9856. }
  9857. }
  9858. }
  9859. out:
  9860. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9861. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9862. authorizeRetryTimes = 0;
  9863. }
  9864. char * strtrimc( char * s )
  9865. {
  9866. char * p1 = s;
  9867. char * p2 = s;
  9868. while(*p1 != '\0')
  9869. {
  9870. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9871. {
  9872. if(*p1 != ',')
  9873. {
  9874. p1 ++;
  9875. }
  9876. else
  9877. {
  9878. break;
  9879. }
  9880. }
  9881. if(*p1 != ',')
  9882. {
  9883. * p2 ++ = *p1 ++;
  9884. //printf("p2=%s\n",p2);
  9885. }
  9886. else
  9887. {
  9888. break;
  9889. }
  9890. }
  9891. *p2 = '\0';
  9892. return (s);
  9893. }
  9894. void handleBootNotificationResponse(char *payload, int gun_index)
  9895. {
  9896. mtrace();
  9897. char statusStr[12]={0};
  9898. char currentTimeStr[30]={0};
  9899. int intervalInt = 0;
  9900. struct tm tp;
  9901. char buf[28]={0};
  9902. char timebuf[50]={0};
  9903. DEBUG_INFO("handleBootNotificationResponse...\n");
  9904. json_object *BootNotification;
  9905. BootNotification = json_tokener_parse(payload);
  9906. if(!is_error(BootNotification))
  9907. {
  9908. // Required data
  9909. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9910. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9911. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9912. }
  9913. json_object_put(BootNotification);
  9914. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9915. BootNotificationInterval = intervalInt;
  9916. HeartBeatWaitTime = intervalInt;
  9917. //write back to ShmOCPP16Data->BootNotification
  9918. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9919. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9920. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9921. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9922. {
  9923. server_sign = TRUE;
  9924. server_pending =FALSE;
  9925. }
  9926. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9927. {
  9928. server_pending = TRUE;
  9929. }
  9930. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9931. tp.tm_isdst = -1;
  9932. //time_t utc = mktime(&tp);
  9933. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9934. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9935. sprintf(timebuf,"date -s '%s'",buf);
  9936. system(timebuf);
  9937. srand(time(NULL));
  9938. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9939. //==============================================
  9940. // RTC sync
  9941. //==============================================
  9942. system("/sbin/hwclock -w --systohc");
  9943. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9944. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9945. }
  9946. void handleDataTransferResponse(char *payload, int gun_index)
  9947. {
  9948. char sstr[160]={0};//sstr[200]={ 0 };
  9949. int c = 0;
  9950. char *loc;
  9951. DEBUG_INFO("handleDataTransferResponse ...\n");
  9952. loc = strstr(payload, "status");
  9953. printf("loc=%s\n",loc);
  9954. c = 0;
  9955. while (loc[3+strlen("status")+c] != '\"')
  9956. {
  9957. sstr[c] = loc[3+strlen("status")+c];
  9958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9959. c++;
  9960. }
  9961. sstr[c] = '\0';
  9962. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9963. }
  9964. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9965. {
  9966. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9967. //struct json_object *obj;
  9968. // obj = json_tokener_parse(payload);
  9969. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9970. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9971. //No fields are defined.
  9972. }
  9973. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9974. {
  9975. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9976. //struct json_object *obj;
  9977. // obj = json_tokener_parse(payload);
  9978. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9979. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9980. //No fields are defined.
  9981. }
  9982. void handleHeartbeatResponse(char *payload, int gun_index)
  9983. {
  9984. mtrace();
  9985. struct tm tp;
  9986. char buf[28]={0};
  9987. char timebuf[50]={0};
  9988. DEBUG_INFO("handleHeartbeatResponse...\n");
  9989. json_object *Heartbeat;
  9990. Heartbeat = json_tokener_parse(payload);
  9991. if(!is_error(Heartbeat))
  9992. {
  9993. // Required data
  9994. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9995. }
  9996. json_object_put(BootNotification);
  9997. if(FirstHeartBeat == 0)
  9998. {
  9999. FirstHeartBeat = 1;
  10000. DEBUG_INFO("FirstHeartBeat \n");
  10001. }
  10002. HeartBeatWithNOResponse = 0;
  10003. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10004. tp.tm_isdst = -1;
  10005. //time_t utc = mktime(&tp);
  10006. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10007. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10008. sprintf(timebuf,"date -s '%s'",buf);
  10009. system(timebuf);
  10010. //==============================================
  10011. // RTC sync
  10012. //==============================================
  10013. system("/sbin/hwclock -w --systohc");
  10014. //===============================================
  10015. //Print Out HeartBeat log
  10016. //===============================================
  10017. {
  10018. double diff_t;
  10019. struct tm tp,tp1;
  10020. // BootNotification Receive Time
  10021. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10022. tp.tm_isdst = -1;
  10023. time_t BootNotificationReceiveTime = mktime(&tp);
  10024. //HeartBeat Receive Time
  10025. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10026. tp1.tm_isdst = -1;
  10027. time_t HeartBeatReceiveTime = mktime(&tp1);
  10028. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10029. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10030. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10031. {
  10032. HeartBeatCountPerHour = (int)diff_t / 3600;
  10033. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10034. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10035. }
  10036. }
  10037. }
  10038. void handleMeterValuesResponse(char *payload, int gun_index)
  10039. {
  10040. mtrace();
  10041. DEBUG_INFO("handleMeterValuesResponse...\n");
  10042. }
  10043. void handleStartTransactionResponse(char *payload, int gun_index)
  10044. {
  10045. mtrace();
  10046. //int transactionIdInt = 0;
  10047. FILE *outfile;
  10048. char data[100]={0};
  10049. DEBUG_INFO("handleStartTransactionResponse...\n");
  10050. json_object *StartTransaction;
  10051. StartTransaction = json_tokener_parse(payload);
  10052. if(!is_error(StartTransaction))
  10053. {
  10054. // Required data
  10055. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10056. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10057. // Optional data
  10058. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10059. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10060. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10061. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10062. }
  10063. json_object_put(StartTransaction);
  10064. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10065. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10066. //-----------Start : write to the Queue TransactionId file -----------------//
  10067. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10068. {}
  10069. else
  10070. {
  10071. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10072. if(log == NULL)
  10073. {
  10074. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10075. return ;
  10076. }
  10077. else
  10078. {
  10079. fclose(log);
  10080. }
  10081. }
  10082. // open file for writing
  10083. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10084. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10085. {
  10086. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10087. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10088. fputs(data, outfile);
  10089. fclose (outfile);
  10090. }
  10091. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10092. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10093. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10094. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10095. }
  10096. void handleStatusNotificationResponse(char *payload, int gun_index)
  10097. {
  10098. mtrace();
  10099. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10100. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10101. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10102. }
  10103. void handleStopTransactionnResponse(char *payload, int gun_index)
  10104. {
  10105. mtrace();
  10106. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10107. json_object *StopTransaction;
  10108. StopTransaction = json_tokener_parse(payload);
  10109. if(!is_error(StopTransaction))
  10110. {
  10111. // Optional data
  10112. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10113. {
  10114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10115. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10116. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10117. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10119. }
  10120. }
  10121. json_object_put(StopTransaction);
  10122. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10123. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10124. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10125. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10126. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10127. }
  10128. //==========================================
  10129. // Handle Error routine
  10130. //==========================================
  10131. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10132. {
  10133. mtrace();
  10134. #ifdef SystemLogMessage
  10135. DEBUG_INFO("errorCode: %s\n", errorCode);
  10136. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10137. DEBUG_INFO("errorDetails: %s\n", payload);
  10138. #endif
  10139. }
  10140. //===============================================
  10141. // Common routine
  10142. //===============================================
  10143. int initialConfigurationTable(void)
  10144. {
  10145. //clock_t start_t, end_t, total_t;
  10146. FILE *fp;
  10147. FILE *outfile;
  10148. char str[200]={0};
  10149. char sstr[100]={0};
  10150. int c = 0;
  10151. char *loc;
  10152. DEBUG_INFO("initialConfigurationTable...\n");
  10153. //start_t = clock();
  10154. //printf("Starting of the program, start_t = %ld\n", start_t);
  10155. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10156. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10157. {
  10158. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10159. if(outfile == NULL)
  10160. {
  10161. DEBUG_INFO("Error opening file\n");
  10162. return FALSE;
  10163. }
  10164. /*Core Profile*/
  10165. //AllowOfflineTxForUnknownId
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10167. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10171. //AuthorizationCacheEnabled
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10176. //AuthorizeRemoteTxRequests
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10181. //BlinkRepeat
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10186. //ClockAlignedDataInterval
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10191. //ConnectionTimeOut
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10196. //GetConfigurationMaxKeys
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10201. // HeartbeatInterval
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10206. // LightIntensity
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10211. // LocalAuthorizeOffline
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10216. // LocalPreAuthorize
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10221. // MaxEnergyOnInvalidId
  10222. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10225. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10227. // MeterValuesAlignedData
  10228. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10232. // MeterValuesAlignedDataMaxLength
  10233. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "6");
  10237. // MeterValuesSampledData
  10238. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10242. // MeterValuesSampledDataMaxLength
  10243. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10247. // MeterValueSampleInterval
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10252. // MinimumStatusDuration
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10256. server_cycle_Status = 120; //StatusNotification cycle
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10258. // NumberOfConnectors
  10259. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10262. {
  10263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10264. }
  10265. else
  10266. {
  10267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10268. }
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10270. // ResetRetries
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10275. // ConnectorPhaseRotation
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10280. // ConnectorPhaseRotationMaxLength
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10285. // StopTransactionOnEVSideDisconnect
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10290. // StopTransactionOnInvalidId
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10295. // StopTxnAlignedData
  10296. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10300. // StopTxnAlignedDataMaxLength
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10305. // StopTxnSampledData
  10306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10310. // StopTxnSampledDataMaxLength
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10314. {
  10315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10316. }
  10317. else
  10318. {
  10319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10320. }
  10321. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10323. // SupportedFeatureProfiles
  10324. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10328. // SupportedFeatureProfilesMaxLength
  10329. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10333. // TransactionMessageAttempts
  10334. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10337. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10339. // TransactionMessageRetryInterval
  10340. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10343. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10345. // UnlockConnectorOnEVSideDisconnect
  10346. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10350. // WebSocketPingInterval
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10355. //* Local Auth List Management Profile*/
  10356. #if 0
  10357. //For OCTT Test Case
  10358. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10361. #endif
  10362. #if 1
  10363. //LocalAuthListEnabled
  10364. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10368. #endif
  10369. //LocalAuthListMaxLength
  10370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10374. //SendLocalListMaxLength
  10375. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "50");
  10379. //ReserveConnectorZeroSupported
  10380. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10384. //* Smart Charging Profile */
  10385. //ChargeProfileMaxStackLevel
  10386. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10390. // ChargingScheduleAllowedChargingRateUnit
  10391. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10395. // ChargingScheduleMaxPeriods
  10396. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10400. // ConnectorSwitch3to1PhaseSupported
  10401. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10405. // MaxChargingProfilesInstalled
  10406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10410. fclose(outfile);
  10411. }
  10412. else
  10413. {
  10414. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10415. char keystr[60]={0};
  10416. char readonlystr[10]={0};
  10417. char valuestr[100]={0};
  10418. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10419. if(fp == NULL) {
  10420. DEBUG_INFO("Error opening file");
  10421. return FALSE;
  10422. }
  10423. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10424. {
  10425. //DEBUG_INFO("Get Configuration \n");
  10426. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10427. //*************************key*********************************/
  10428. loc = strstr(str, "key");
  10429. c = 0;
  10430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10431. while (loc[strlen("key")+3+c] != '\"')
  10432. {
  10433. sstr[c] = loc[strlen("key")+3+c];
  10434. c++;
  10435. }
  10436. sstr[c] = '\0';
  10437. strcpy(keystr,sstr);
  10438. //*************************readonly*********************************/
  10439. loc = strstr(str, "readonly");
  10440. c = 0;
  10441. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10442. while (loc[strlen("readonly")+2+c] != ',')
  10443. {
  10444. sstr[c] = loc[strlen("readonly")+2+c];
  10445. c++;
  10446. }
  10447. sstr[c] = '\0';
  10448. strcpy(readonlystr,sstr);
  10449. //*************************value*********************************/
  10450. loc = strstr(str, "value");
  10451. c = 0;
  10452. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10453. while (loc[strlen("value")+3+c] != '\"')
  10454. {
  10455. sstr[c] = loc[strlen("value")+3+c];
  10456. c++;
  10457. }
  10458. sstr[c] = '\0';
  10459. strcpy(valuestr,sstr);
  10460. // DEBUG_INFO("keystr=%s\n",keystr);
  10461. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10462. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10463. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10464. {
  10465. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10468. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10469. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10470. }
  10471. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10472. {
  10473. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10476. }
  10477. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10478. {
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10481. }
  10482. if(strcmp(keystr, "BlinkRepeat") == 0)
  10483. {
  10484. //Charger.BlinkRepeat = Integer.parseInt(value);
  10485. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10487. }
  10488. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10489. {
  10490. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10492. }
  10493. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10494. {
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10497. }
  10498. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10499. {
  10500. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10502. }
  10503. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10504. {
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10507. HeartBeatWaitTime = atoi(valuestr);
  10508. }
  10509. if(strcmp(keystr, "LightIntensity") == 0)
  10510. {
  10511. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10513. }
  10514. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10515. {
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10518. }
  10519. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10520. {
  10521. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10523. }
  10524. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10528. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10529. }
  10530. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10531. {
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10534. }
  10535. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10536. {
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10539. }
  10540. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10541. {
  10542. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10544. }
  10545. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10546. {
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10549. }
  10550. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10551. {
  10552. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10554. }
  10555. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10556. {
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10559. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10560. }
  10561. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10562. {
  10563. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10565. }
  10566. if(strcmp(keystr, "ResetRetries") == 0)
  10567. {
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10570. }
  10571. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10572. {
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10575. }
  10576. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10577. {
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10580. }
  10581. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10582. {
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10585. }
  10586. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10590. }
  10591. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10595. }
  10596. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10600. }
  10601. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10605. }
  10606. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10610. }
  10611. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10615. }
  10616. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10620. }
  10621. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10625. TransactionMessageAttemptsValue = atoi(valuestr);
  10626. }
  10627. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10628. {
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10631. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10632. }
  10633. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10637. }
  10638. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10639. {
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10642. }
  10643. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10644. {
  10645. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10647. }
  10648. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10649. {
  10650. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10652. }
  10653. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10654. {
  10655. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10657. }
  10658. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10659. {
  10660. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10662. }
  10663. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10664. {
  10665. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10667. }
  10668. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10669. {
  10670. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10672. }
  10673. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10674. {
  10675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10677. }
  10678. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10679. {
  10680. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10682. }
  10683. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10684. {
  10685. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10687. }
  10688. }
  10689. fclose(fp);
  10690. }
  10691. return 0;
  10692. }
  10693. void StoreConfigurationTable(void)
  10694. {
  10695. FILE *outfile;
  10696. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10697. if(outfile == NULL)
  10698. {
  10699. DEBUG_INFO("Error opening file");
  10700. return ;
  10701. }
  10702. /*Core Profile*/
  10703. //AllowOfflineTxForUnknownId
  10704. /*
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10706. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10709. */
  10710. //DEBUG_INFO("data=%s\n",data);
  10711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10712. //AuthorizationCacheEnabled
  10713. /*
  10714. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10717. */
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10719. //AuthorizeRemoteTxRequests
  10720. /*
  10721. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10724. */
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10726. //BlinkRepeat
  10727. /*
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10731. */
  10732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10733. //ClockAlignedDataInterval
  10734. /*
  10735. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10738. */
  10739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10740. //ConnectionTimeOut
  10741. /*
  10742. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10745. */
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10747. //GetConfigurationMaxKeys
  10748. /*
  10749. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10752. */
  10753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10754. // HeartbeatInterval
  10755. /*
  10756. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10759. */
  10760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10761. // LightIntensity
  10762. /*
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10766. */
  10767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10768. // LocalAuthorizeOffline
  10769. /*
  10770. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10773. */
  10774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10775. // LocalPreAuthorize
  10776. /*
  10777. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10780. */
  10781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10782. // MaxEnergyOnInvalidId
  10783. /*
  10784. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10787. */
  10788. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10790. // MeterValuesAlignedData
  10791. /*
  10792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10795. */
  10796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10797. // MeterValuesAlignedDataMaxLength
  10798. /*
  10799. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10802. */
  10803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10804. // MeterValuesSampledData
  10805. /*
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10809. */
  10810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10811. // MeterValuesSampledDataMaxLength
  10812. /*
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10816. */
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10818. // MeterValueSampleInterval
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10825. // MinimumStatusDuration
  10826. /*
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10830. */
  10831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10832. // NumberOfConnectors
  10833. /*
  10834. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10837. {
  10838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10839. }
  10840. else
  10841. {
  10842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10843. }
  10844. */
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10846. // ResetRetries
  10847. /*
  10848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10851. */
  10852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10853. // ConnectorPhaseRotation
  10854. /*
  10855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10858. */
  10859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10860. // ConnectorPhaseRotationMaxLength
  10861. /*
  10862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10865. */
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10867. // StopTransactionOnEVSideDisconnect
  10868. /*
  10869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10872. */
  10873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10874. // StopTransactionOnInvalidId
  10875. /*
  10876. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10879. */
  10880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10881. // StopTxnAlignedData
  10882. /*
  10883. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10886. */
  10887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10888. // StopTxnAlignedDataMaxLength
  10889. /*
  10890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10893. */
  10894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10895. // StopTxnSampledData
  10896. /*
  10897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10900. */
  10901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10902. // StopTxnSampledDataMaxLength
  10903. /*
  10904. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10907. */
  10908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10909. // SupportedFeatureProfiles
  10910. /*
  10911. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10914. */
  10915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10916. // SupportedFeatureProfilesMaxLength
  10917. /*
  10918. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10921. */
  10922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10923. // TransactionMessageAttempts
  10924. /*
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10928. */
  10929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10930. // TransactionMessageRetryInterval
  10931. /*
  10932. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10935. */
  10936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10937. // UnlockConnectorOnEVSideDisconnect
  10938. /*
  10939. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10942. */
  10943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10944. // WebSocketPingInterval
  10945. /*
  10946. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10949. */
  10950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10951. //* Local Auth List Management Profile*/
  10952. //LocalAuthListEnabled
  10953. /*
  10954. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10957. */
  10958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10959. //LocalAuthListMaxLength
  10960. /*
  10961. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10964. */
  10965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10966. //SendLocalListMaxLength
  10967. /*
  10968. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10971. */
  10972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10973. //ReserveConnectorZeroSupported
  10974. /*
  10975. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10978. */
  10979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10980. //* Smart Charging Profile */
  10981. //ChargeProfileMaxStackLevel
  10982. /*
  10983. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10986. */
  10987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10988. // ChargingScheduleAllowedChargingRateUnit
  10989. /*
  10990. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10993. */
  10994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10995. // ChargingScheduleMaxPeriods
  10996. /*
  10997. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11000. */
  11001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11002. // ConnectorSwitch3to1PhaseSupported
  11003. /*
  11004. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11007. */
  11008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11009. // MaxChargingProfilesInstalled
  11010. /*
  11011. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11014. */
  11015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11016. fclose(outfile);
  11017. }
  11018. void getKeyValue(char *keyReq)
  11019. {
  11020. int isEmpty = FALSE;
  11021. int isKnowKey = FALSE;
  11022. DEBUG_INFO("keyReq = %s\n", keyReq);
  11023. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11024. isEmpty = TRUE;
  11025. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11032. }
  11033. else
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11036. }
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11038. isKnowKey = TRUE;
  11039. }
  11040. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11041. {
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11047. }
  11048. else
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11051. }
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11053. isKnowKey = TRUE;
  11054. }
  11055. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11062. }
  11063. else
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11066. }
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11068. isKnowKey = TRUE;
  11069. }
  11070. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11077. }
  11078. else
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11081. }
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11083. isKnowKey = TRUE;
  11084. }
  11085. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11092. }
  11093. else
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11096. }
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11098. isKnowKey = TRUE;
  11099. }
  11100. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11107. }
  11108. else
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11111. }
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11113. isKnowKey = TRUE;
  11114. }
  11115. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11122. }
  11123. else
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11126. }
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11128. isKnowKey = TRUE;
  11129. }
  11130. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11137. }
  11138. else
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11141. }
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11143. isKnowKey = TRUE;
  11144. }
  11145. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11152. }
  11153. else
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11156. }
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11158. isKnowKey = TRUE;
  11159. }
  11160. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11167. }
  11168. else
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11171. }
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11173. isKnowKey = TRUE;
  11174. }
  11175. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11182. }
  11183. else
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11186. }
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11188. isKnowKey = TRUE;
  11189. }
  11190. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11197. }
  11198. else
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11201. }
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11203. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11348. }
  11349. else
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11352. }
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11354. isKnowKey = TRUE;
  11355. }
  11356. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11363. }
  11364. else
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11367. }
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11369. isKnowKey = TRUE;
  11370. }
  11371. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11444. isKnowKey = TRUE;
  11445. }
  11446. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11453. }
  11454. else
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11457. }
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11459. isKnowKey = TRUE;
  11460. }
  11461. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11468. }
  11469. else
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11472. }
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11474. isKnowKey = TRUE;
  11475. }
  11476. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11483. }
  11484. else
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11487. }
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11489. isKnowKey = TRUE;
  11490. }
  11491. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11498. }
  11499. else
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11502. }
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11504. isKnowKey = TRUE;
  11505. }
  11506. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11513. }
  11514. else
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11517. }
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11519. isKnowKey = TRUE;
  11520. }
  11521. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11528. }
  11529. else
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11532. }
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11534. isKnowKey = TRUE;
  11535. }
  11536. #if 1
  11537. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11541. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11544. }
  11545. else
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11548. }
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11550. isKnowKey = TRUE;
  11551. }
  11552. #endif
  11553. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11554. {
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11557. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11560. }
  11561. else
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11564. }
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11566. isKnowKey = TRUE;
  11567. }
  11568. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11569. {
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11572. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11575. }
  11576. else
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11579. }
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11581. isKnowKey = TRUE;
  11582. }
  11583. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11584. {
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11587. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11590. }
  11591. else
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11594. }
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11596. isKnowKey = TRUE;
  11597. }
  11598. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11599. {
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11602. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11605. }
  11606. else
  11607. {
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11609. }
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11611. isKnowKey = TRUE;
  11612. }
  11613. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11614. {
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11617. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11620. }
  11621. else
  11622. {
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11624. }
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11626. isKnowKey = TRUE;
  11627. }
  11628. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11632. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11635. }
  11636. else
  11637. {
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11639. }
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11641. isKnowKey = TRUE;
  11642. }
  11643. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11647. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11650. }
  11651. else
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11654. }
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11656. isKnowKey = TRUE;
  11657. }
  11658. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11662. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11665. }
  11666. else
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11669. }
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11671. isKnowKey = TRUE;
  11672. }
  11673. //=========================================================
  11674. if(!isEmpty && !isKnowKey)
  11675. {
  11676. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11677. strcpy(unknownkey[UnknownKeynum], keyReq);
  11678. UnknownKeynum = UnknownKeynum + 1;
  11679. }
  11680. }
  11681. void processUnkownKey(void)
  11682. {
  11683. DEBUG_INFO("processUnkownKey...\n");
  11684. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11685. for(int index=0; index < UnknownKeynum; index++)
  11686. {
  11687. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11688. {
  11689. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11690. }
  11691. }
  11692. }
  11693. int setKeyValue(char *key, char *value)
  11694. {
  11695. int isSuccess = NotSupported;
  11696. int check_ascii=0;
  11697. char str[10]={0};
  11698. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11699. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11700. {
  11701. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11703. {
  11704. strcpy(str, (const char*)value);
  11705. for(int i = 0; str[i]; i++){
  11706. str[i] = tolower(str[i]);
  11707. }
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11709. isSuccess = ConfigurationStatus_Accepted;
  11710. }
  11711. else
  11712. {
  11713. isSuccess = ConfigurationStatus_Rejected;
  11714. }
  11715. }
  11716. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11717. {
  11718. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11720. {
  11721. strcpy(str, (const char*)value);
  11722. for(int i = 0; str[i]; i++){
  11723. str[i] = tolower(str[i]);
  11724. }
  11725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11726. isSuccess = ConfigurationStatus_Accepted;
  11727. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11728. }
  11729. else
  11730. {
  11731. isSuccess = ConfigurationStatus_Rejected;
  11732. }
  11733. }
  11734. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11735. {
  11736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11737. {
  11738. strcpy(str, (const char*)value);
  11739. for(int i = 0; str[i]; i++)
  11740. {
  11741. str[i] = tolower(str[i]);
  11742. }
  11743. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11745. isSuccess = ConfigurationStatus_Accepted;
  11746. }
  11747. else
  11748. {
  11749. isSuccess = ConfigurationStatus_Rejected;
  11750. }
  11751. }
  11752. if(strcmp(key, "BlinkRepeat") == 0)
  11753. {
  11754. //Charger.BlinkRepeat = Integer.parseInt(value);
  11755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11756. {
  11757. check_ascii = value[0];
  11758. if( (check_ascii < 48) || (check_ascii > 57) )
  11759. {
  11760. isSuccess = ConfigurationStatus_Rejected;
  11761. }
  11762. else
  11763. {
  11764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11765. isSuccess = ConfigurationStatus_Accepted;
  11766. }
  11767. }
  11768. else
  11769. {
  11770. isSuccess = ConfigurationStatus_Rejected;
  11771. }
  11772. }
  11773. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11774. {
  11775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11776. {
  11777. check_ascii = value[0];
  11778. if( (check_ascii < 48) || (check_ascii > 57) )
  11779. {
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. else
  11783. {
  11784. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11786. isSuccess = ConfigurationStatus_Accepted;
  11787. }
  11788. }
  11789. else
  11790. {
  11791. isSuccess = ConfigurationStatus_Rejected;
  11792. }
  11793. }
  11794. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11795. {
  11796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11797. {
  11798. check_ascii = value[0];
  11799. if( (check_ascii < 48) || (check_ascii > 57) )
  11800. {
  11801. isSuccess = ConfigurationStatus_Rejected;
  11802. }
  11803. else
  11804. {
  11805. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11807. isSuccess = ConfigurationStatus_Accepted;
  11808. }
  11809. }
  11810. else
  11811. {
  11812. isSuccess = ConfigurationStatus_Rejected;
  11813. }
  11814. }
  11815. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11816. {
  11817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11818. {
  11819. check_ascii = value[0];
  11820. if( (check_ascii < 48) || (check_ascii > 57) )
  11821. {
  11822. isSuccess = ConfigurationStatus_Rejected;
  11823. }
  11824. else
  11825. {
  11826. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11828. isSuccess = ConfigurationStatus_Accepted;
  11829. }
  11830. }
  11831. else
  11832. {
  11833. isSuccess = ConfigurationStatus_Rejected;
  11834. }
  11835. }
  11836. if(strcmp(key, "HeartbeatInterval") == 0)
  11837. {
  11838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11839. {
  11840. check_ascii = value[0];
  11841. if( (check_ascii < 48) || (check_ascii > 57) )
  11842. {
  11843. isSuccess = ConfigurationStatus_Rejected;
  11844. }
  11845. else
  11846. {
  11847. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11849. HeartBeatWaitTime = atoi(value);
  11850. isSuccess = ConfigurationStatus_Accepted;
  11851. }
  11852. }
  11853. else
  11854. {
  11855. isSuccess = ConfigurationStatus_Rejected;
  11856. }
  11857. }
  11858. if(strcmp(key, "LightIntensity") == 0)
  11859. {
  11860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11861. {
  11862. check_ascii = value[0];
  11863. if( (check_ascii < 48) || (check_ascii > 57) )
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. else
  11868. {
  11869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11870. isSuccess = ConfigurationStatus_Accepted;
  11871. }
  11872. }
  11873. else
  11874. {
  11875. isSuccess = ConfigurationStatus_Rejected;
  11876. }
  11877. }
  11878. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11879. {
  11880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11881. {
  11882. strcpy(str, (const char*)value);
  11883. for(int i = 0; str[i]; i++)
  11884. {
  11885. str[i] = tolower(str[i]);
  11886. }
  11887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11888. isSuccess = ConfigurationStatus_Accepted;
  11889. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11890. }
  11891. else
  11892. {
  11893. isSuccess = ConfigurationStatus_Rejected;
  11894. }
  11895. }
  11896. if(strcmp(key, "LocalPreAuthorize") == 0)
  11897. {
  11898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11899. {
  11900. strcpy(str, (const char*)value);
  11901. for(int i = 0; str[i]; i++)
  11902. {
  11903. str[i] = tolower(str[i]);
  11904. }
  11905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11906. isSuccess = ConfigurationStatus_Accepted;
  11907. }
  11908. else
  11909. {
  11910. isSuccess = ConfigurationStatus_Rejected;
  11911. }
  11912. }
  11913. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11914. {
  11915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11916. {
  11917. check_ascii = value[0];
  11918. if( (check_ascii < 48) || (check_ascii > 57) )
  11919. {
  11920. isSuccess = ConfigurationStatus_Rejected;
  11921. }
  11922. else
  11923. {
  11924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11925. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11926. isSuccess = ConfigurationStatus_Accepted;
  11927. }
  11928. }
  11929. else
  11930. {
  11931. isSuccess = ConfigurationStatus_Rejected;
  11932. }
  11933. }
  11934. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11935. {
  11936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11937. {
  11938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11939. isSuccess = ConfigurationStatus_Accepted;
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11947. {
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11949. {
  11950. check_ascii = value[0];
  11951. if( (check_ascii < 48) || (check_ascii > 57) )
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. else
  11956. {
  11957. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11959. isSuccess = ConfigurationStatus_Accepted;
  11960. }
  11961. }
  11962. else
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. }
  11967. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11968. {
  11969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11970. {
  11971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11972. isSuccess = ConfigurationStatus_Accepted;
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11982. {
  11983. check_ascii = value[0];
  11984. if( (check_ascii < 48) || (check_ascii > 57) )
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. else
  11989. {
  11990. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11992. isSuccess = ConfigurationStatus_Accepted;
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12003. {
  12004. check_ascii = value[0];
  12005. if( (check_ascii < 48) || (check_ascii > 57) )
  12006. {
  12007. isSuccess = ConfigurationStatus_Rejected;
  12008. }
  12009. else
  12010. {
  12011. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. }
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. if(strcmp(key, "MinimumStatusDuration") == 0)
  12022. {
  12023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12024. {
  12025. check_ascii = value[0];
  12026. if( (check_ascii < 48) || (check_ascii > 57) )
  12027. {
  12028. isSuccess = ConfigurationStatus_Rejected;
  12029. }
  12030. else
  12031. {
  12032. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12033. {
  12034. isSuccess = ConfigurationStatus_Rejected;
  12035. }
  12036. else
  12037. {
  12038. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12040. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12041. isSuccess = ConfigurationStatus_Accepted;
  12042. }
  12043. }
  12044. }
  12045. else
  12046. {
  12047. isSuccess = ConfigurationStatus_Rejected;
  12048. }
  12049. }
  12050. if(strcmp(key, "NumberOfConnectors") == 0)
  12051. {
  12052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].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. //Charger.ResetRetries = Integer.parseInt(value);
  12062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12063. isSuccess = ConfigurationStatus_Accepted;
  12064. }
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "ResetRetries") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12074. {
  12075. check_ascii = value[0];
  12076. if( (check_ascii < 48) || (check_ascii > 57) )
  12077. {
  12078. isSuccess = ConfigurationStatus_Rejected;
  12079. }
  12080. else
  12081. {
  12082. //Charger.ResetRetries = Integer.parseInt(value);
  12083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12084. isSuccess = ConfigurationStatus_Accepted;
  12085. }
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12095. {
  12096. strcpy(str, (const char*)value);
  12097. for(int i = 0; str[i]; i++)
  12098. {
  12099. str[i] = tolower(str[i]);
  12100. }
  12101. if(strcmp(str, "notapplicable")== 0)
  12102. {
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. else if(strcmp(str, "unknown")== 0)
  12107. {
  12108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12109. isSuccess = ConfigurationStatus_Accepted;
  12110. }
  12111. else if(strcmp(str, "rst")== 0)
  12112. {
  12113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12114. isSuccess = ConfigurationStatus_Accepted;
  12115. }
  12116. else if(strcmp(str, "rts")== 0)
  12117. {
  12118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12119. isSuccess = ConfigurationStatus_Accepted;
  12120. }
  12121. else if(strcmp(str, "srt")== 0)
  12122. {
  12123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12124. isSuccess = ConfigurationStatus_Accepted;
  12125. }
  12126. else if(strcmp(str, "str")== 0)
  12127. {
  12128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12129. isSuccess = ConfigurationStatus_Accepted;
  12130. }
  12131. else if(strcmp(str, "trs")== 0)
  12132. {
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12134. isSuccess = ConfigurationStatus_Accepted;
  12135. }
  12136. else if(strcmp(str, "tsr")== 0)
  12137. {
  12138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12139. isSuccess = ConfigurationStatus_Accepted;
  12140. }
  12141. else
  12142. {
  12143. isSuccess = ConfigurationStatus_Rejected;
  12144. }
  12145. }
  12146. else
  12147. {
  12148. isSuccess = ConfigurationStatus_Rejected;
  12149. }
  12150. }
  12151. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12152. {
  12153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12154. {
  12155. check_ascii = value[0];
  12156. if( (check_ascii < 48) || (check_ascii > 57) )
  12157. {
  12158. isSuccess = ConfigurationStatus_Rejected;
  12159. }
  12160. else
  12161. {
  12162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12163. isSuccess = ConfigurationStatus_Accepted;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. }
  12171. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12172. {
  12173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12174. {
  12175. strcpy(str, (const char*)value);
  12176. for(int i = 0; str[i]; i++)
  12177. {
  12178. str[i] = tolower(str[i]);
  12179. }
  12180. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12182. isSuccess = ConfigurationStatus_Accepted;
  12183. }
  12184. else
  12185. {
  12186. isSuccess = ConfigurationStatus_Rejected;
  12187. }
  12188. }
  12189. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12190. {
  12191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12192. {
  12193. strcpy(str, (const char*)value);
  12194. for(int i = 0; str[i]; i++)
  12195. {
  12196. str[i] = tolower(str[i]);
  12197. }
  12198. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. else
  12203. {
  12204. isSuccess = ConfigurationStatus_Rejected;
  12205. }
  12206. }
  12207. if(strcmp(key, "StopTxnAlignedData") == 0)
  12208. {
  12209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12210. {
  12211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12212. isSuccess = ConfigurationStatus_Accepted;
  12213. }
  12214. else
  12215. {
  12216. isSuccess = ConfigurationStatus_Rejected;
  12217. }
  12218. }
  12219. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12220. {
  12221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12222. {
  12223. check_ascii = value[0];
  12224. if( (check_ascii < 48) || (check_ascii > 57) )
  12225. {
  12226. isSuccess = ConfigurationStatus_Rejected;
  12227. }
  12228. else
  12229. {
  12230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12231. isSuccess = ConfigurationStatus_Accepted;
  12232. }
  12233. }
  12234. else
  12235. {
  12236. isSuccess = ConfigurationStatus_Rejected;
  12237. }
  12238. }
  12239. if(strcmp(key, "StopTxnSampledData") == 0)
  12240. {
  12241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12242. {
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12244. isSuccess = ConfigurationStatus_Accepted;
  12245. }
  12246. else
  12247. {
  12248. isSuccess = ConfigurationStatus_Rejected;
  12249. }
  12250. }
  12251. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12252. {
  12253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12254. {
  12255. check_ascii = value[0];
  12256. if( (check_ascii < 48) || (check_ascii > 57) )
  12257. {
  12258. isSuccess = ConfigurationStatus_Rejected;
  12259. }
  12260. else
  12261. {
  12262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12263. isSuccess = ConfigurationStatus_Accepted;
  12264. }
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12272. {
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12274. {
  12275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12276. isSuccess = ConfigurationStatus_Accepted;
  12277. }
  12278. else
  12279. {
  12280. isSuccess = ConfigurationStatus_Rejected;
  12281. }
  12282. }
  12283. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12284. {
  12285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12286. {
  12287. check_ascii = value[0];
  12288. if( (check_ascii < 48) || (check_ascii > 57) )
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. else
  12293. {
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12306. {
  12307. check_ascii = value[0];
  12308. if( (check_ascii < 48) || (check_ascii > 57) )
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. else
  12313. {
  12314. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12316. TransactionMessageAttemptsValue = atoi(value);
  12317. isSuccess = ConfigurationStatus_Accepted;
  12318. }
  12319. }
  12320. else
  12321. {
  12322. isSuccess = ConfigurationStatus_Rejected;
  12323. }
  12324. }
  12325. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12326. {
  12327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12328. {
  12329. check_ascii = value[0];
  12330. if( (check_ascii < 48) || (check_ascii > 57) )
  12331. {
  12332. isSuccess = ConfigurationStatus_Rejected;
  12333. }
  12334. else
  12335. {
  12336. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12338. TransactionMessageRetryIntervalValue = atoi(value);
  12339. isSuccess = ConfigurationStatus_Accepted;
  12340. }
  12341. }
  12342. else
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. }
  12347. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12350. {
  12351. strcpy(str, (const char*)value);
  12352. for(int i = 0; str[i]; i++)
  12353. {
  12354. str[i] = tolower(str[i]);
  12355. }
  12356. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12358. isSuccess = ConfigurationStatus_Accepted;
  12359. }
  12360. else
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. }
  12365. if(strcmp(key, "WebSocketPingInterval") == 0)
  12366. {
  12367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12368. {
  12369. check_ascii = value[0];
  12370. if( (check_ascii < 48) || (check_ascii > 57) )
  12371. {
  12372. isSuccess = ConfigurationStatus_Rejected;
  12373. }
  12374. else
  12375. {
  12376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12377. isSuccess = ConfigurationStatus_Accepted;
  12378. }
  12379. }
  12380. else
  12381. {
  12382. isSuccess = ConfigurationStatus_Rejected;
  12383. }
  12384. }
  12385. #if 0
  12386. //For OCPP Test Case
  12387. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12390. {
  12391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12392. isSuccess = ConfigurationStatus_Accepted;
  12393. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12394. }
  12395. else
  12396. {
  12397. isSuccess = ConfigurationStatus_Rejected;
  12398. }
  12399. }
  12400. #endif
  12401. #if 1
  12402. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12403. {
  12404. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12405. {
  12406. strcpy(str, (const char*)value);
  12407. for(int i = 0; str[i]; i++)
  12408. {
  12409. str[i] = tolower(str[i]);
  12410. }
  12411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12412. isSuccess = ConfigurationStatus_Accepted;
  12413. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12414. }
  12415. else
  12416. {
  12417. isSuccess = ConfigurationStatus_Rejected;
  12418. }
  12419. }
  12420. #endif
  12421. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12422. {
  12423. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12424. {
  12425. check_ascii = value[0];
  12426. if( (check_ascii < 48) || (check_ascii > 57) )
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. else
  12431. {
  12432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12433. isSuccess = ConfigurationStatus_Accepted;
  12434. }
  12435. }
  12436. else
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. }
  12441. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12442. {
  12443. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12444. {
  12445. check_ascii = value[0];
  12446. if( (check_ascii < 48) || (check_ascii > 57) )
  12447. {
  12448. isSuccess = ConfigurationStatus_Rejected;
  12449. }
  12450. else
  12451. {
  12452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12453. isSuccess = ConfigurationStatus_Accepted;
  12454. }
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12464. {
  12465. strcpy(str, (const char*)value);
  12466. for(int i = 0; str[i]; i++)
  12467. {
  12468. str[i] = tolower(str[i]);
  12469. }
  12470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12471. isSuccess = ConfigurationStatus_Accepted;
  12472. }
  12473. else
  12474. {
  12475. isSuccess = ConfigurationStatus_Rejected;
  12476. }
  12477. }
  12478. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12479. {
  12480. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12481. {
  12482. check_ascii = value[0];
  12483. if( (check_ascii < 48) || (check_ascii > 57) )
  12484. {
  12485. isSuccess = ConfigurationStatus_Rejected;
  12486. }
  12487. else
  12488. {
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12490. isSuccess = ConfigurationStatus_Accepted;
  12491. }
  12492. }
  12493. else
  12494. {
  12495. isSuccess = ConfigurationStatus_Rejected;
  12496. }
  12497. }
  12498. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12499. {
  12500. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12503. isSuccess = ConfigurationStatus_Accepted;
  12504. }
  12505. else
  12506. {
  12507. isSuccess = ConfigurationStatus_Rejected;
  12508. }
  12509. }
  12510. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12511. {
  12512. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12513. {
  12514. check_ascii = value[0];
  12515. if( (check_ascii < 48) || (check_ascii > 57) )
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. else
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12522. isSuccess = ConfigurationStatus_Accepted;
  12523. }
  12524. }
  12525. else
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. }
  12530. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12531. {
  12532. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12533. {
  12534. strcpy(str, (const char*)value);
  12535. for(int i = 0; str[i]; i++)
  12536. {
  12537. str[i] = tolower(str[i]);
  12538. }
  12539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12540. isSuccess = ConfigurationStatus_Accepted;
  12541. }
  12542. else
  12543. {
  12544. isSuccess = ConfigurationStatus_Rejected;
  12545. }
  12546. }
  12547. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12548. {
  12549. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12550. {
  12551. check_ascii = value[0];
  12552. if( (check_ascii < 48) || (check_ascii > 57) )
  12553. {
  12554. isSuccess = ConfigurationStatus_Rejected;
  12555. }
  12556. else
  12557. {
  12558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12559. isSuccess = ConfigurationStatus_Accepted;
  12560. }
  12561. }
  12562. else
  12563. {
  12564. isSuccess = ConfigurationStatus_Rejected;
  12565. }
  12566. }
  12567. return isSuccess;
  12568. }
  12569. int TransactionMessageAttemptsGet(void)
  12570. {
  12571. return TransactionMessageAttemptsValue;
  12572. }
  12573. int FirstHeartBeatResponse(void)
  12574. {
  12575. return FirstHeartBeat;
  12576. }
  12577. int TransactionMessageRetryIntervalGet(void)
  12578. {
  12579. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12580. }
  12581. int ReadHttpStatus(int sock)
  12582. {
  12583. //char c;
  12584. char buff[1024]="",*ptr=buff+1;
  12585. int bytes_received, status;
  12586. DEBUG_INFO("Begin Response ..\n");
  12587. while((bytes_received = recv(sock, ptr, 1, 0))){
  12588. if(bytes_received==-1){
  12589. perror("ReadHttpStatus");
  12590. exit(1);
  12591. }
  12592. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12593. ptr++;
  12594. }
  12595. *ptr=0;
  12596. ptr=buff+1;
  12597. sscanf(ptr,"%*s %d ", &status);
  12598. DEBUG_INFO("%s\n",ptr);
  12599. DEBUG_INFO("status=%d\n",status);
  12600. DEBUG_INFO("End Response ..\n");
  12601. return (bytes_received>0)?status:0;
  12602. }
  12603. //the only filed that it parsed is 'Content-Length'
  12604. int ParseHeader(int sock)
  12605. {
  12606. //char c;
  12607. char buff[1024]="",*ptr=buff+4;
  12608. int bytes_received;
  12609. DEBUG_INFO("Begin HEADER ..\n");
  12610. while((bytes_received = recv(sock, ptr, 1, 0))){
  12611. if(bytes_received==-1){
  12612. perror("Parse Header");
  12613. exit(1);
  12614. }
  12615. if(
  12616. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12617. (ptr[-1]=='\r') && (*ptr=='\n' )
  12618. ) break;
  12619. ptr++;
  12620. }
  12621. *ptr=0;
  12622. ptr=buff+4;
  12623. //printf("%s",ptr);
  12624. if(bytes_received){
  12625. ptr=strstr(ptr,"Content-Length:");
  12626. if(ptr){
  12627. sscanf(ptr,"%*s %d",&bytes_received);
  12628. }else
  12629. bytes_received=-1; //unknown size
  12630. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12631. }
  12632. DEBUG_INFO("End HEADER ..\n");
  12633. return bytes_received ;
  12634. }
  12635. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12636. {
  12637. char rmFileCmd[100]={0};
  12638. char FilePath[100]={0};
  12639. char ftpbuf[200];
  12640. int systemresult;
  12641. //DEBUG_INFO("filename=%s\n",filename);
  12642. //DEBUG_INFO("url=%s\n",url);
  12643. sprintf(FilePath,"/mnt/%s",filename);
  12644. if((access(FilePath,F_OK))!=-1)
  12645. {
  12646. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12647. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12648. system(rmFileCmd);
  12649. }
  12650. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12651. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12652. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12653. systemresult = system(ftpbuf);
  12654. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12655. if(systemresult != 0)
  12656. {
  12657. DEBUG_INFO("http DownLoad error!\n");
  12658. return FALSE;
  12659. }
  12660. return TRUE;
  12661. }
  12662. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12663. {
  12664. char rmFileCmd[100]={0};
  12665. char FilePath[100]={0};
  12666. char ftpbuf[200];
  12667. int systemresult;
  12668. //char temp[100];
  12669. sprintf(FilePath,"/mnt/%s",filename);
  12670. if((access(FilePath,F_OK))!=-1)
  12671. {
  12672. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12673. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12674. system(rmFileCmd);
  12675. }
  12676. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12677. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12678. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12679. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12680. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12681. systemresult = system(ftpbuf);
  12682. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12683. if(systemresult != 0)
  12684. {
  12685. printf("wget error!\n");
  12686. return FALSE;
  12687. }
  12688. return TRUE;
  12689. }
  12690. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12691. {
  12692. char rmFileCmd[100]={0};
  12693. char FilePath[100]={0};
  12694. char ftpbuf[200];
  12695. int systemresult;
  12696. //DEBUG_INFO("filename=%s\n",filename);
  12697. //DEBUG_INFO("url=%s\n",url);
  12698. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12699. if((access(FilePath,F_OK))!=-1)
  12700. {
  12701. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12702. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12703. system(rmFileCmd);
  12704. }
  12705. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12706. if(fp == NULL)
  12707. {
  12708. DEBUG_INFO("log is NULL\n");
  12709. return FALSE;
  12710. }
  12711. else
  12712. {
  12713. fprintf(fp, "%s\n", url);
  12714. fprintf(fp, "%s\n", filename);
  12715. fclose(fp);
  12716. }
  12717. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12718. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12719. systemresult = system(ftpbuf);
  12720. DEBUG_INFO("systemresult = %d\n",systemresult);
  12721. if(systemresult != 0)
  12722. {
  12723. DEBUG_INFO("http upload error!\n");
  12724. return FALSE;
  12725. }
  12726. return TRUE;
  12727. }
  12728. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12729. {
  12730. struct hostent* server;
  12731. char *IPbuffer;
  12732. char ftpbuf[200];
  12733. int systemresult;
  12734. // To retrieve host information
  12735. server = gethostbyname(location);
  12736. // To convert an Internet network
  12737. // address into ASCII string
  12738. IPbuffer = inet_ntoa(*((struct in_addr*)
  12739. server->h_addr_list[0]));
  12740. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12741. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12742. /* format : ftpput -u username -p passwd IP target source*/
  12743. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12744. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12745. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12746. systemresult = system(ftpbuf);
  12747. DEBUG_INFO("systemresult=%d\n",systemresult);
  12748. if(systemresult != 0)
  12749. {
  12750. DEBUG_INFO("ftpput error!\n");
  12751. return FALSE;
  12752. }
  12753. return TRUE;
  12754. }
  12755. /**
  12756. * Place the contents of the specified file into a memory buffer
  12757. *
  12758. * @param[in] filename The path and name of the file to read
  12759. * @param[out] filebuffer A pointer to the contents in memory
  12760. * @return status 0 success, 1 on failure
  12761. */
  12762. int get_file_contents(const char* filename, char** outbuffer) {
  12763. FILE* file = NULL;
  12764. long filesize;
  12765. const int blocksize = 1;
  12766. size_t readsize;
  12767. char* filebuffer;
  12768. // Open the file
  12769. file = fopen(filename, "r");
  12770. if (NULL == file)
  12771. {
  12772. printf("'%s' not opened\n", filename);
  12773. exit(EXIT_FAILURE);
  12774. }
  12775. // Determine the file size
  12776. fseek(file, 0, SEEK_END);
  12777. filesize = ftell(file);
  12778. rewind (file);
  12779. // Allocate memory for the file contents
  12780. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12781. *outbuffer = filebuffer;
  12782. if (filebuffer == NULL)
  12783. {
  12784. fputs ("malloc out-of-memory", stderr);
  12785. exit(EXIT_FAILURE);
  12786. }
  12787. // Read in the file
  12788. readsize = fread(filebuffer, blocksize, filesize, file);
  12789. if (readsize != filesize)
  12790. {
  12791. fputs ("didn't read file completely",stderr);
  12792. exit(EXIT_FAILURE);
  12793. }
  12794. // Clean exit
  12795. fclose(file);
  12796. return EXIT_SUCCESS;
  12797. }
  12798. static int selectSqlCount = 0;
  12799. static int callback(void *data, int argc, char **argv, char **azColName){
  12800. int i;
  12801. //printf("%s: ", (const char*)data);
  12802. selectSqlCount = argc;
  12803. for(i = 0; i<argc; i++){
  12804. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12805. }
  12806. //printf("\n");
  12807. return 0;
  12808. }
  12809. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12810. //int i;
  12811. //printf("%s:\n", (const char*)data);
  12812. localversion = argv[5] ? atoi(argv[5]) : 0;
  12813. //printf("localversion=%d\n", localversion);
  12814. return 0;
  12815. }
  12816. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12817. //int i;
  12818. //printf("%s:\n", (const char*)data);
  12819. //idTag
  12820. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12821. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12822. //parentIdTag
  12823. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12824. //expir_date
  12825. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12826. //status
  12827. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12828. //version
  12829. idTagQuery.listVersionInt = atoi(argv[5]);
  12830. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12831. return 0;
  12832. }
  12833. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12834. {
  12835. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12836. // printf("localversion=%d\n", localversion);
  12837. return 0;
  12838. }
  12839. //=========================================
  12840. // Sqlite3 related function
  12841. //=========================================
  12842. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12843. {
  12844. for (int i = 0; i < n_columns; i++)
  12845. {
  12846. DEBUG_INFO("%s/t", col_values[i]);
  12847. }
  12848. DEBUG_INFO("/n");
  12849. return 0;
  12850. }
  12851. void OCPP_getListVerion()
  12852. {
  12853. int rc = 0;
  12854. // const char* data = "Callback function called";
  12855. char sql[100];
  12856. char zErrMsg[100];
  12857. memset(sql, 0, 100);
  12858. memset(zErrMsg, 0, 100);
  12859. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12860. /* Execute SQL statement */
  12861. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12862. if( rc != SQLITE_OK )
  12863. {
  12864. DEBUG_INFO("SQL error: %s", zErrMsg);
  12865. }
  12866. }
  12867. void OCPP_getIdTag(char idTag[])
  12868. {
  12869. int rc = 0;
  12870. // const char* data = "Callback function called";
  12871. char sql[100];
  12872. char zErrMsg[100];
  12873. memset(sql, 0, 100);
  12874. memset(zErrMsg, 0, 100);
  12875. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12876. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12877. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12878. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12879. /* Execute SQL statement */
  12880. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12881. if( rc != SQLITE_OK )
  12882. {
  12883. DEBUG_INFO("SQL error: %s", zErrMsg);
  12884. }
  12885. //return ver;
  12886. }
  12887. void OCPP_get_TableAuthlocalAllData(void)
  12888. {
  12889. int rc = 0;
  12890. char sql[100];
  12891. char zErrMsg[100];
  12892. memset(sql, 0, 100);
  12893. memset(zErrMsg, 0, 100);
  12894. sprintf(sql,"select * from ocpp_auth_local ");
  12895. /* Execute SQL statement */
  12896. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12897. if( rc != SQLITE_OK )
  12898. {
  12899. DEBUG_INFO("SQL error: %s", zErrMsg);
  12900. }
  12901. //return ver;
  12902. }
  12903. int OCPP_cleanLocalList()
  12904. {
  12905. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12906. char *errMsg = 0;
  12907. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12908. if (SQLITE_OK != rc)
  12909. {
  12910. DEBUG_INFO("%s\n",errMsg);
  12911. return FALSE;
  12912. }
  12913. return TRUE;
  12914. }
  12915. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12916. {
  12917. int isSuccess = FALSE;
  12918. int ret = 0;
  12919. //const char* data = "Callback function called";
  12920. char sql[300];
  12921. char zErrMsg[200];
  12922. memset(sql, 0, 300);
  12923. memset(zErrMsg, 0, 200);
  12924. 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);
  12925. //* Execute SQL statement */
  12926. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12927. if( ret != SQLITE_OK )
  12928. {
  12929. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12930. return isSuccess;
  12931. }
  12932. memset(sql, 0, 300);
  12933. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12934. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12935. if( ret != SQLITE_OK )
  12936. {
  12937. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12938. return isSuccess;
  12939. }
  12940. isSuccess = TRUE;
  12941. return isSuccess;
  12942. }
  12943. void OCPP_deleteIdTag(char idTag[])
  12944. {
  12945. //int ver = 0;
  12946. //int isSuccess = FALSE;
  12947. int rc = 0;
  12948. char sql[100];
  12949. char zErrMsg[100];
  12950. memset(sql, 0, 100);
  12951. memset(zErrMsg, 0, 100);
  12952. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12953. //* Execute SQL statement */
  12954. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12955. if( rc != SQLITE_OK )
  12956. {
  12957. DEBUG_INFO("SQL error: %s", zErrMsg);
  12958. }
  12959. }
  12960. int GetOcppServerURL()
  12961. {
  12962. int result = FALSE;
  12963. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12964. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12965. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12966. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12967. {
  12968. #if 1
  12969. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12970. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12971. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12972. #endif
  12973. result = TRUE;
  12974. goto End;
  12975. }
  12976. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12977. {
  12978. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12979. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12980. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12981. result = TRUE;
  12982. goto End;
  12983. }
  12984. else
  12985. {
  12986. strcpy(OcppHost,"");
  12987. }
  12988. End:
  12989. return result;
  12990. }
  12991. int GetOcppPath()
  12992. {
  12993. int result = FALSE;
  12994. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12995. {
  12996. if(OcppTempPath == NULL)
  12997. {
  12998. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12999. }
  13000. else
  13001. {
  13002. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13003. }
  13004. result = TRUE;
  13005. goto End;
  13006. }
  13007. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13008. {
  13009. if(OcppTempPath == NULL)
  13010. {
  13011. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13012. }
  13013. else
  13014. {
  13015. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13016. }
  13017. result = TRUE;
  13018. goto End;
  13019. }
  13020. else
  13021. {
  13022. strcpy(OcppPath,"");
  13023. }
  13024. End:
  13025. return result;
  13026. }
  13027. int GetOcppPort()
  13028. {
  13029. return OcppPort;
  13030. }
  13031. int GetOcppConnStatus(void)
  13032. {
  13033. return ShmOCPP16Data->OcppConnStatus;
  13034. }
  13035. void SetOcppConnStatus(uint8_t status)
  13036. {
  13037. ShmOCPP16Data->OcppConnStatus = status;
  13038. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13039. }
  13040. int GetHeartBeatWithNOResponse(void)
  13041. {
  13042. return HeartBeatWithNOResponse;
  13043. }
  13044. void SetHeartBeatWithNOResponse(void)
  13045. {
  13046. HeartBeatWithNOResponse = 0;
  13047. }
  13048. void GetStartTransactionIdTag(int gun_index)
  13049. {
  13050. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13051. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13052. }
  13053. int GetTransactionId(int gunindex, unsigned char idTag[])
  13054. {
  13055. char ch;
  13056. FILE *fptr1;
  13057. int temptransactionId;
  13058. char str[100]={0};
  13059. temptransactionId = 0;
  13060. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13061. {
  13062. DEBUG_INFO("IdTag is empty.\n");
  13063. return temptransactionId;
  13064. }
  13065. /*------ Read the file ----------------*/
  13066. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13067. if (!fptr1)
  13068. {
  13069. DEBUG_INFO("QueueTransactionId file open error.\n");
  13070. //printf(" File not found or unable to open the input file!!\n");
  13071. return temptransactionId;
  13072. }
  13073. ch=fgetc(fptr1);
  13074. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13075. rewind(fptr1);
  13076. if(ch!=EOF)
  13077. {
  13078. // printf("%c",ch);
  13079. while (fgets(str, 100, fptr1) != NULL)
  13080. {
  13081. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13082. if(str[0]=='\0')
  13083. {
  13084. break;
  13085. }
  13086. char *revbuf[8] = {0}; //存放分割後的子字串
  13087. int num = 0;//分割後子字串的個數
  13088. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13089. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13090. {
  13091. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13092. {
  13093. temptransactionId = atoi(revbuf[2]);
  13094. break;
  13095. }
  13096. }
  13097. }
  13098. }
  13099. fclose(fptr1);
  13100. /*------- End of reading ---------------*/
  13101. return temptransactionId;
  13102. }
  13103. void SetTransactionIdZero(int transactionId)
  13104. {
  13105. char ch;
  13106. FILE *fptr1, *fptr2;
  13107. int temptransactionId = 0;
  13108. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13109. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13110. if (!fptr1)
  13111. {
  13112. //printf(" File not found or unable to open the input file!!\n");
  13113. return ;
  13114. }
  13115. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13116. if (!fptr2)
  13117. {
  13118. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13119. fclose(fptr1);
  13120. return ;
  13121. }
  13122. ch=fgetc(fptr1);
  13123. rewind(fptr1);
  13124. if(ch!=EOF)
  13125. {
  13126. // copy all contents to the temporary file except the specific line
  13127. while (fgets(str, 100, fptr1) != NULL)
  13128. {
  13129. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13130. if(str[0]=='\0')
  13131. {
  13132. break;
  13133. }
  13134. char *revbuf[8] = {0};
  13135. int num = 0;
  13136. strcpy(strtemp, str);
  13137. splitstring(str,",",revbuf,&num);
  13138. if(revbuf[2][0] != '\0')
  13139. {
  13140. temptransactionId = atoi(revbuf[2]);
  13141. if(transactionId != temptransactionId)
  13142. {
  13143. fprintf(fptr2, "%s\n", strtemp);
  13144. }
  13145. }
  13146. }
  13147. }
  13148. fclose(fptr1);
  13149. fclose(fptr2);
  13150. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13151. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13152. /*------ Read the file ----------------*/
  13153. }
  13154. int InternetDisconnect(void)
  13155. {
  13156. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13157. }
  13158. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13159. void storeTempStopTransaction(int gun_index)
  13160. {
  13161. char guid[37]={0};
  13162. int tempIndex = 0;
  13163. DEBUG_INFO("storeTempStopTransaction...\n");
  13164. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13165. //ENERGY_ACTIVE_IMPORT_REGISTER
  13166. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13167. if(gunType[gun_index] == 'J')
  13168. {
  13169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13170. {
  13171. tempIndex = ((gun_index==2) ? 1: 0);
  13172. }
  13173. else
  13174. {
  13175. tempIndex = gun_index;
  13176. }
  13177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13178. {
  13179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13180. {
  13181. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13182. }
  13183. }// END OF CHAdeMO_QUANTITY
  13184. }
  13185. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13186. {
  13187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13188. {
  13189. tempIndex = ((gun_index==2) ? 1: 0);
  13190. }
  13191. else
  13192. {
  13193. tempIndex = gun_index;
  13194. }
  13195. for (int index = 0; index < CCS_QUANTITY; index++)
  13196. {
  13197. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13198. {
  13199. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13200. }
  13201. }// END OF CCS_QUANTITY
  13202. }
  13203. else if(gunType[gun_index] == 'G')
  13204. {
  13205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13206. {
  13207. tempIndex = ((gun_index==2) ? 1: 0);
  13208. }
  13209. else
  13210. {
  13211. tempIndex = gun_index;
  13212. }
  13213. for (int index = 0; index < GB_QUANTITY; index++)
  13214. {
  13215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13216. {
  13217. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13218. }
  13219. }// END OF GB_QUANTITY
  13220. }
  13221. else
  13222. {
  13223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13224. {
  13225. tempIndex = 2;
  13226. }
  13227. else
  13228. {
  13229. tempIndex = gun_index;
  13230. }
  13231. for (int index = 0; index < AC_QUANTITY; index++)
  13232. {
  13233. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13234. {
  13235. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13236. }
  13237. }// END OF AC_QUANTITY
  13238. }
  13239. //Stop Transaction Time
  13240. struct timeval tmnow;
  13241. struct tm *tm;
  13242. char buf[28];//, usec_buf[6];
  13243. gettimeofday(&tmnow, NULL);
  13244. time_t t;
  13245. t = time(NULL);
  13246. /*UTC time and date*/
  13247. tm = gmtime(&t);
  13248. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13250. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13252. random_uuid(guid);
  13253. /***********************************transactionData******************************************************/
  13254. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13256. //=================================
  13257. //1. Transaction_Begin
  13258. //=================================
  13259. // Energy.Active.Export.Interval
  13260. //idx_sample=0;
  13261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13264. 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*/]);
  13265. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13266. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13267. {
  13268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13269. }
  13270. else
  13271. {
  13272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13273. }
  13274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13276. //=================================
  13277. //2. Transaction_End
  13278. //=================================
  13279. //2.1 Current.Export
  13280. //idx_sample=1;
  13281. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13282. if(gunType[gun_index] == 'J')
  13283. {
  13284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13285. {
  13286. tempIndex = ((gun_index==2) ? 1: 0);
  13287. }
  13288. else
  13289. {
  13290. tempIndex = gun_index;
  13291. }
  13292. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13293. {
  13294. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13295. {
  13296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13297. }
  13298. }// End of for CHAdeMO_QUANTITY
  13299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13300. }
  13301. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13302. {
  13303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13304. {
  13305. tempIndex = ((gun_index==2) ? 1: 0);
  13306. }
  13307. else
  13308. {
  13309. tempIndex = gun_index;
  13310. }
  13311. for (int index = 0; index < CCS_QUANTITY; index++)
  13312. {
  13313. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13314. {
  13315. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13316. }
  13317. }// End of for CCS_QUANTITY
  13318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13319. }
  13320. else if(gunType[gun_index] == 'G')
  13321. {
  13322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13323. {
  13324. tempIndex = ((gun_index==2) ? 1: 0);
  13325. }
  13326. else
  13327. {
  13328. tempIndex = gun_index;
  13329. }
  13330. for (int index = 0; index < GB_QUANTITY; index++)
  13331. {
  13332. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13333. {
  13334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13335. }
  13336. }// End of for GB_QUANTITY
  13337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13338. }
  13339. else
  13340. {
  13341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13342. {
  13343. tempIndex = 2;
  13344. }
  13345. else
  13346. {
  13347. tempIndex = gun_index;
  13348. }
  13349. for (int index = 0; index < AC_QUANTITY; index++)
  13350. {
  13351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13352. {
  13353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13354. }
  13355. }// End of for AC_QUANTITY
  13356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13357. }
  13358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13361. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13364. //2.2 Energy.Active.Export.Interval
  13365. //idx_sample=2;
  13366. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13367. if(gunType[gun_index] == 'J')
  13368. {
  13369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13370. {
  13371. tempIndex = ((gun_index==2) ? 1: 0);
  13372. }
  13373. else
  13374. {
  13375. tempIndex = gun_index;
  13376. }
  13377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13378. {
  13379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13380. {
  13381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13382. }
  13383. }// END OF CHAdeMO_QUANTITY
  13384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13385. }
  13386. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13387. {
  13388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13389. {
  13390. tempIndex = ((gun_index==2) ? 1: 0);
  13391. }
  13392. else
  13393. {
  13394. tempIndex = gun_index;
  13395. }
  13396. for (int index = 0; index < CCS_QUANTITY; index++)
  13397. {
  13398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13399. {
  13400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13401. }
  13402. }// END OF CCS_QUANTITY
  13403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13404. }
  13405. else if(gunType[gun_index] == 'G')
  13406. {
  13407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13408. {
  13409. tempIndex = ((gun_index==2) ? 1: 0);
  13410. }
  13411. else
  13412. {
  13413. tempIndex = gun_index;
  13414. }
  13415. for (int index = 0; index < GB_QUANTITY; index++)
  13416. {
  13417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13418. {
  13419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13420. }
  13421. }// END OF GB_QUANTITY
  13422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13423. }
  13424. else
  13425. {
  13426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13427. {
  13428. tempIndex = 2;
  13429. }
  13430. else
  13431. {
  13432. tempIndex = gun_index;
  13433. }
  13434. for (int index = 0; index < AC_QUANTITY; index++)
  13435. {
  13436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13437. {
  13438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13439. }
  13440. }// END OF AC_QUANTITY
  13441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13442. }
  13443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13446. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13449. //2.3 Power.Active.Export
  13450. //idx_sample=3;
  13451. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13452. if(gunType[gun_index] == 'J')
  13453. {
  13454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13455. {
  13456. tempIndex = ((gun_index==2) ? 1: 0);
  13457. }
  13458. else
  13459. {
  13460. tempIndex = gun_index;
  13461. }
  13462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13463. {
  13464. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13465. {
  13466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13467. }
  13468. } // End for CHAdeMO_QUANTITY
  13469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13470. }
  13471. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13472. {
  13473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13474. {
  13475. tempIndex = ((gun_index==2) ? 1: 0);
  13476. }
  13477. else
  13478. {
  13479. tempIndex = gun_index;
  13480. }
  13481. for (int index = 0; index < CCS_QUANTITY; index++)
  13482. {
  13483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13484. {
  13485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13486. }
  13487. } // END for CCS_QUANTITY
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13489. }
  13490. else if(gunType[gun_index] == 'G')
  13491. {
  13492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13493. {
  13494. tempIndex = ((gun_index==2) ? 1: 0);
  13495. }
  13496. else
  13497. {
  13498. tempIndex = gun_index;
  13499. }
  13500. for (int index = 0; index < GB_QUANTITY; index++)
  13501. {
  13502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13503. {
  13504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13505. }
  13506. }// END for GB_QUANTITY
  13507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13508. }
  13509. else
  13510. {
  13511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13512. {
  13513. tempIndex = 2;
  13514. }
  13515. else
  13516. {
  13517. tempIndex = gun_index;
  13518. }
  13519. for (int index = 0; index < AC_QUANTITY; index++)
  13520. {
  13521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13522. {
  13523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13524. }
  13525. } // END for AC_QUANTITY
  13526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13527. }
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13531. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13534. //2.4 Voltage
  13535. //idx_sample=4;
  13536. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13537. if(gunType[gun_index] == 'J')
  13538. {
  13539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13540. {
  13541. tempIndex = ((gun_index==2) ? 1: 0);
  13542. }
  13543. else
  13544. {
  13545. tempIndex = gun_index;
  13546. }
  13547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13548. {
  13549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13550. {
  13551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13552. }
  13553. } // END OF FOR CHAdeMO_QUANTITY
  13554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13555. }
  13556. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13557. {
  13558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13559. {
  13560. tempIndex = ((gun_index==2) ? 1: 0);
  13561. }
  13562. else
  13563. {
  13564. tempIndex = gun_index;
  13565. }
  13566. for (int index = 0; index < CCS_QUANTITY; index++)
  13567. {
  13568. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13569. {
  13570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13571. }
  13572. } // END OF FOR CCS_QUANTITY
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13574. }
  13575. else if(gunType[gun_index] == 'G')
  13576. {
  13577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13578. {
  13579. tempIndex = ((gun_index==2) ? 1: 0);
  13580. }
  13581. else
  13582. {
  13583. tempIndex = gun_index;
  13584. }
  13585. for (int index = 0; index < GB_QUANTITY; index++)
  13586. {
  13587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13588. {
  13589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13590. }
  13591. } // END OF FOR GB_QUANTITY
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13593. }
  13594. else
  13595. {
  13596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13597. {
  13598. tempIndex = 2;
  13599. }
  13600. else
  13601. {
  13602. tempIndex = gun_index;
  13603. }
  13604. for (int index = 0; index < AC_QUANTITY; index++)
  13605. {
  13606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13607. {
  13608. 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
  13609. }
  13610. } // END OF FOR AC_QUANTITY
  13611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13612. }
  13613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13616. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13619. //2.5 SoC
  13620. //idx_sample=5;
  13621. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13622. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13623. {
  13624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13625. {
  13626. tempIndex = ((gun_index==2) ? 1: 0);
  13627. }
  13628. else
  13629. {
  13630. tempIndex = gun_index;
  13631. }
  13632. if(gunType[gun_index] == 'J')
  13633. {
  13634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13635. {
  13636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13637. {
  13638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13639. }
  13640. }
  13641. }
  13642. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13643. {
  13644. for (int index = 0; index < CCS_QUANTITY; index++)
  13645. {
  13646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13647. {
  13648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13649. }
  13650. }
  13651. }
  13652. else if(gunType[gun_index] == 'G')
  13653. {
  13654. for (int index = 0; index < GB_QUANTITY; index++)
  13655. {
  13656. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13657. {
  13658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13659. }
  13660. }
  13661. }
  13662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13668. } // END FOR DC CASE
  13669. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13670. {
  13671. 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\"}]}]}]"
  13672. ,gun_index+1
  13673. ,MESSAGE_TYPE_CALL
  13674. ,guid
  13675. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13676. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13677. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13679. ,"PowerLoss"
  13680. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13701. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13702. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13703. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13704. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13705. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13706. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13707. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13723. );
  13724. }
  13725. else
  13726. {
  13727. 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\"}]}]}]"
  13728. ,gun_index+1
  13729. ,MESSAGE_TYPE_CALL
  13730. ,guid
  13731. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13732. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13733. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13735. ,"PowerLoss"
  13736. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13772. );
  13773. }
  13774. // Check File "TempStopTransaction" Exist
  13775. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13776. {
  13777. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13778. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13779. }
  13780. else
  13781. {
  13782. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13783. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13784. if(log == NULL)
  13785. {
  13786. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13787. return ;
  13788. }
  13789. else
  13790. {
  13791. fclose(log);
  13792. }
  13793. }
  13794. //Add TempStopTransaction | Update TempStopTransaction
  13795. // open file for writing
  13796. FILE *outfile;
  13797. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13798. //DEBUG_INFO("data = %s\n", queuedata);
  13799. fputs(queuedata, outfile);
  13800. fputs("\n", outfile);
  13801. fclose (outfile);
  13802. }
  13803. void checkTempStopTransaction(int gun_index)
  13804. {
  13805. FILE *fptr1;
  13806. char ch;
  13807. char str[1200]={0};
  13808. char guid[37]={0};
  13809. char tempdata[65]={0};
  13810. char connectorStr[2]={0};
  13811. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13812. //TempStopTransaction格式: 槍號,StopTransaction封包
  13813. if (!fptr1)
  13814. {
  13815. //printf(" File not found or unable to open the input file!!\n");
  13816. return ;
  13817. }
  13818. ch=fgetc(fptr1);
  13819. //printf(" Now the content of the file %s is : \n",fname);
  13820. rewind(fptr1);
  13821. if(ch!=EOF)
  13822. {
  13823. // copy all contents to the temporary file except the specific line
  13824. while (fgets(str, 1200, fptr1) != NULL)
  13825. {
  13826. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13827. if(str[0]=='\0')
  13828. {
  13829. break;
  13830. }
  13831. //TempStopTransaction格式: 槍號,StopTransaction封包
  13832. strncpy(connectorStr, str, 1);
  13833. if(atoi(connectorStr) != (gun_index+1))
  13834. {
  13835. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13836. return ;
  13837. }
  13838. //random_uuid(guid);
  13839. strncpy(guid, str+6, 36); //copy guid
  13840. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13841. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13842. {
  13843. DEBUG_INFO("StopTransaction mapitem pass\n");
  13844. }
  13845. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13846. memset(str,0,ARRAY_SIZE(str));
  13847. }
  13848. }
  13849. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13850. fclose(fptr1);
  13851. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13852. }
  13853. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13854. {
  13855. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13856. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13857. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13858. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13859. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13860. }
  13861. int GetWebSocketPingInterval(void)
  13862. {
  13863. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13864. }
  13865. int GetServerSign(void)
  13866. {
  13867. return server_sign;
  13868. }
  13869. void SetServerSign(int value)
  13870. {
  13871. server_sign = value;
  13872. }
  13873. int GetBootNotificationInterval(void)
  13874. {
  13875. return BootNotificationInterval;
  13876. }
  13877. int GetInternetConn(void)
  13878. {
  13879. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13880. }
  13881. void InitialSystemValue(void)
  13882. {
  13883. int connectorIndex = 0;
  13884. //int valueASCII = 0;
  13885. server_cycle_Status = 120;
  13886. gunTotalNumber=0;
  13887. SystemInitial = 0;
  13888. localversion=0;
  13889. BootNotificationInterval = 0;
  13890. authorizeRetryTimes = 0;
  13891. GunStatusInterval = 10;
  13892. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13893. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13894. //Hear Beat
  13895. HeartBeatWithNOResponse = 0;
  13896. HeartBeatCountPerHour = 0;
  13897. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13898. FirstHeartBeat = 0;
  13899. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13900. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13901. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  13902. memset(statusModeChage, 0, sizeof(statusModeChage));
  13903. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13904. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13905. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13906. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13907. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13908. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13909. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13910. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13911. memset(gunType, 0, sizeof(gunType));
  13912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13913. {
  13914. //check connector / socket type (index: 8, 9, 10)
  13915. for(int index=7; index <10 ; index++)
  13916. {
  13917. if(index != 8)
  13918. {
  13919. // DC Connector
  13920. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13921. {
  13922. SystemInitial = SystemInitial + 1;
  13923. gunTotalNumber = gunTotalNumber + 1;
  13924. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13925. connectorIndex = connectorIndex + 1;
  13926. }
  13927. }
  13928. else
  13929. {
  13930. // AC Connector
  13931. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13932. {
  13933. SystemInitial = SystemInitial + 1;
  13934. gunTotalNumber = gunTotalNumber + 1;
  13935. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13936. connectorIndex = connectorIndex + 1;
  13937. }
  13938. }
  13939. }
  13940. //DEBUG_INFO("DC ...\n");
  13941. }
  13942. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13943. {
  13944. //check connector / socket type (index: 8, 9, 10)
  13945. for(int index=7; index <10 ; index++)
  13946. {
  13947. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13948. {
  13949. SystemInitial = SystemInitial + 1;
  13950. gunTotalNumber = gunTotalNumber + 1;
  13951. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13952. connectorIndex = connectorIndex + 1;
  13953. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13954. }
  13955. }
  13956. }
  13957. //Status && ConnectorPlugIn Setting
  13958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13959. {
  13960. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13961. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13962. }
  13963. for (int index = 0; index < CCS_QUANTITY; index++)
  13964. {
  13965. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13966. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13967. }
  13968. for (int index = 0; index < GB_QUANTITY; index++)
  13969. {
  13970. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13971. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13972. }
  13973. for (int index = 0; index < AC_QUANTITY; index++)
  13974. {
  13975. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13976. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13977. }
  13978. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13979. {
  13980. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13981. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13982. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13983. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13984. }
  13985. // Charger PRE_SYS_MODE
  13986. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13987. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13988. clientTime.Heartbeat=time((time_t*)NULL);
  13989. sleep(1);
  13990. }
  13991. void LWS_Send(char * str)
  13992. {
  13993. //=====================================================
  13994. // Check InternetConn 0: disconnected, 1: connected
  13995. //====================================================
  13996. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13997. {
  13998. DEBUG_INFO("offline now !!!\n");
  13999. return;
  14000. }
  14001. pthread_mutex_lock(&lock_send);
  14002. memset(SendBuffer, 0, SendBufLen);
  14003. sprintf((char *)SendBuffer, "%s", str);
  14004. pthread_mutex_unlock(&lock_send);
  14005. lws_callback_on_writable(wsi_client);
  14006. lws_service(context, 0);
  14007. //sleep(1);
  14008. }