MessageHandler.c 613 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. //===============================
  100. // Local List Version
  101. //===============================
  102. static int localversion=0;
  103. static char idTagAuthorization[32]={0};
  104. //===============================
  105. // OCPP Path
  106. //===============================
  107. extern char OcppPath[160];
  108. extern char OcppProtocol[10];
  109. extern char OcppHost[50];
  110. extern char OcppTempPath[50];
  111. int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. int authenrequest = FALSE;
  124. int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. int TransactionMessageAttemptsValue = 0;
  152. int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  904. {
  905. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  906. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  907. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  908. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  909. }
  910. // Charger PRE_SYS_MODE
  911. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  912. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  913. clientTime.Heartbeat=time((time_t*)NULL);
  914. #if 0
  915. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  916. {
  917. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  918. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  919. }
  920. #endif
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  923. // allocate Configuration memory address
  924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  929. {
  930. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  931. DEBUG_INFO("DC ...\n");
  932. }
  933. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  934. {
  935. SystemInitial = AC_QUANTITY;
  936. DEBUG_INFO("AC ...\n");
  937. }
  938. //Status / ConnectorPlugIn Setting
  939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  940. {
  941. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  942. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  943. }
  944. for (int index = 0; index < CCS_QUANTITY; index++)
  945. {
  946. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  947. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  948. }
  949. for (int index = 0; index < GB_QUANTITY; index++)
  950. {
  951. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  952. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  953. }
  954. for (int index = 0; index < AC_QUANTITY; index++)
  955. {
  956. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  957. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  958. }
  959. return result;
  960. }
  961. int ProcessShareMemory()
  962. {
  963. if(InitShareMemory() == FAIL)
  964. {
  965. #ifdef SystemLogMessage
  966. DEBUG_ERROR("InitShareMemory NG\n");
  967. #endif
  968. if(ShmStatusCodeData!=NULL)
  969. {
  970. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  971. }
  972. sleep(5);
  973. return FAIL;
  974. }
  975. return PASS;
  976. }
  977. //---------------------------------------------
  978. // new:
  979. // enum SYSTEM_STATUS
  980. // {
  981. // SYS_MODE_BOOTING = 0,
  982. // SYS_MODE_IDLE = 1,
  983. // SYS_MODE_AUTHORIZING = 2,
  984. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  985. // SYS_MODE_REASSIGN = 4,
  986. // SYS_MODE_PREPARING = 5,
  987. // SYS_MODE_PREPARE_FOR_EV = 6,
  988. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  989. // SYS_MODE_CHARGING = 8,
  990. // SYS_MODE_TERMINATING = 9,
  991. // SYS_MODE_COMPLETE = 10,
  992. // SYS_MODE_ALARM = 11,
  993. // SYS_MODE_FAULT = 12,
  994. // SYS_MODE_RESERVATION = 13,
  995. // SYS_MODE_BOOKING = 14,
  996. // SYS_MODE_MAINTAIN = 15,
  997. // SYS_MODE_DEBUG = 16,
  998. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  999. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1000. // SYS_MODE_UPDATE = 19
  1001. // };
  1002. //
  1003. //
  1004. //-----------------------------------------
  1005. void CheckSystemValue(void)
  1006. {
  1007. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1008. //int IdleModeCnt = 0;
  1009. char filenmae[100]={0};
  1010. char str[100]={0};
  1011. //===============================
  1012. // send Heartbeat
  1013. //===============================
  1014. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1015. {
  1016. printf("Heartbeat !!!\n");
  1017. //parameter for test
  1018. sendHeartbeatRequest(0);
  1019. //==============================================
  1020. // Reset Waiting Time
  1021. //==============================================
  1022. clientTime.Heartbeat=time((time_t*)NULL);
  1023. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1024. }
  1025. #if 0
  1026. //==============================================
  1027. // Update firmware request
  1028. //==============================================
  1029. if(isUpdateRequest == TRUE )
  1030. {
  1031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1032. {
  1033. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1034. {
  1035. //check SystemStatus
  1036. /*************************DC*******************************/
  1037. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1038. {
  1039. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1040. {
  1041. IdleModeCnt = IdleModeCnt + 1;
  1042. }
  1043. }
  1044. for (int index = 0; index < CCS_QUANTITY; index++)
  1045. {
  1046. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1047. {
  1048. IdleModeCnt = IdleModeCnt + 1;
  1049. }
  1050. }
  1051. for (int index = 0; index < GB_QUANTITY; index++)
  1052. {
  1053. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1054. {
  1055. IdleModeCnt = IdleModeCnt + 1;
  1056. }
  1057. }
  1058. }
  1059. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1060. {
  1061. isUpdateRequest = FALSE;
  1062. }
  1063. }
  1064. else
  1065. {
  1066. /*************************AC*******************************/
  1067. for (int index = 0; index < AC_QUANTITY; index++)
  1068. {
  1069. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1070. {
  1071. IdleModeCnt = IdleModeCnt + 1;
  1072. }
  1073. }
  1074. if(IdleModeCnt == AC_QUANTITY)
  1075. {
  1076. isUpdateRequest = FALSE;
  1077. }
  1078. }
  1079. }
  1080. #endif
  1081. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1082. {
  1083. //===============================
  1084. // CSU Trigger Reset Conf
  1085. //===============================
  1086. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1087. {
  1088. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1089. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1090. {
  1091. server_sign = FALSE;
  1092. }
  1093. }
  1094. //===============================
  1095. // CSU Trigger Authorize Request
  1096. //===============================
  1097. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. if(authorizeRetryTimes < 3)
  1102. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1103. }
  1104. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1105. {
  1106. authorizeRetryTimes = 0;
  1107. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1108. server_sign = FALSE;
  1109. }
  1110. 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))
  1111. {
  1112. sendAuthorizeRequest(0);
  1113. }
  1114. //===============================
  1115. // CSU Trigger Smart Charging Profilw
  1116. //===============================
  1117. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1118. {
  1119. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1120. GetChargingProfileRequest(gun_index);
  1121. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1122. }
  1123. //==============================================
  1124. // Charger start transaction
  1125. //==============================================
  1126. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1127. {
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1129. sendStartTransactionRequest(gun_index);
  1130. clientTime.StartTransaction = time((time_t*)NULL);
  1131. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1132. }
  1133. //==============================================
  1134. // Charger stop transaction
  1135. //==============================================
  1136. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1137. {
  1138. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1139. sendStopTransactionRequest(gun_index);
  1140. clientTime.StopTransaction = time((time_t*)NULL);
  1141. }
  1142. //==============================================
  1143. // Charger status report
  1144. //==============================================
  1145. /* Check Mode Change */
  1146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1147. {
  1148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1149. {
  1150. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1151. {
  1152. 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]*/ )
  1153. {
  1154. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1155. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1156. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1158. statusModeChage[gun_index] = TRUE;
  1159. }
  1160. }
  1161. }
  1162. for (int index = 0; index < CCS_QUANTITY; index++)
  1163. {
  1164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1165. {
  1166. 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]*/ )
  1167. {
  1168. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1169. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1170. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }
  1176. for (int index = 0; index < GB_QUANTITY; index++)
  1177. {
  1178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1179. {
  1180. 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]*/ )
  1181. {
  1182. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1183. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1184. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1185. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1186. statusModeChage[gun_index] = TRUE;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. else //AC
  1192. {
  1193. for (int index = 0; index < AC_QUANTITY; index++)
  1194. {
  1195. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1196. {
  1197. 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]*/ )
  1198. {
  1199. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1200. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1201. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1202. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1203. statusModeChage[gun_index] = TRUE;
  1204. }
  1205. }
  1206. }// END OF FOR
  1207. }// END OF ELSE
  1208. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1209. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1210. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1211. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1212. {
  1213. if(SystemInitial != 0)
  1214. SystemInitial = SystemInitial -1;
  1215. sendStatusNotificationRequest(gun_index);
  1216. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1217. statusModeChage[gun_index] = FALSE;
  1218. }
  1219. //==============================================
  1220. // Meter report
  1221. //==============================================
  1222. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1223. {
  1224. //check Transaction active
  1225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1226. {
  1227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1228. {
  1229. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1230. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1231. {
  1232. meterValueSend[gun_index] =1;
  1233. }
  1234. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1235. {
  1236. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1237. if((access(filenmae,F_OK))!=-1)
  1238. {
  1239. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1240. sprintf(str,"rm -f %s",filenmae);
  1241. system(str);
  1242. }
  1243. }
  1244. }// End for CHAdeMO
  1245. for (int index = 0; index < CCS_QUANTITY; index++)
  1246. {
  1247. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1248. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1249. {
  1250. meterValueSend[gun_index] =1;
  1251. }
  1252. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1253. {
  1254. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1255. if((access(filenmae,F_OK))!=-1)
  1256. {
  1257. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1258. sprintf(str,"rm -f %s",filenmae);
  1259. system(str);
  1260. }
  1261. }
  1262. } // End for CCS
  1263. for (int index = 0; index < GB_QUANTITY; index++)
  1264. {
  1265. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1266. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1267. {
  1268. meterValueSend[gun_index] =1;
  1269. }
  1270. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1271. {
  1272. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1273. if((access(filenmae,F_OK))!=-1)
  1274. {
  1275. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1276. sprintf(str,"rm -f %s",filenmae);
  1277. system(str);
  1278. }
  1279. }
  1280. }// End for GB
  1281. }
  1282. else
  1283. {
  1284. for (int index = 0; index < AC_QUANTITY; index++)
  1285. {
  1286. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1287. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1288. {
  1289. meterValueSend[gun_index] =1;
  1290. }
  1291. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1292. {
  1293. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1294. if((access(filenmae,F_OK))!=-1)
  1295. {
  1296. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1297. sprintf(str,"rm -f %s",filenmae);
  1298. system(str);
  1299. }
  1300. }
  1301. }//End for AC
  1302. }//END OF ELSE
  1303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1304. if(meterValueSend[gun_index] == 1)
  1305. sendMeterValuesRequest(gun_index);
  1306. }
  1307. //==============================================
  1308. // Check Connector reserved
  1309. //==============================================
  1310. //===============================
  1311. // Check if Reserve is expired
  1312. //===============================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1314. {
  1315. double diff_t;
  1316. struct tm tp;
  1317. // current time
  1318. time_t t = time(NULL);
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. if(diff_t <= 0)
  1324. {
  1325. DEBUG_INFO("reserve expired !!! \n");
  1326. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1327. }
  1328. }//END OF Check if Reserve is expired
  1329. //==========================================
  1330. // csu trigger FirmwareStatusNotificationReq
  1331. //==========================================
  1332. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1333. {
  1334. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1335. }
  1336. //==========================================
  1337. // csu trigger CancelReservationConf
  1338. //==========================================
  1339. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1340. {
  1341. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1342. }
  1343. //==========================================
  1344. // csu trigger ChangeAvailabilityConf
  1345. //==========================================
  1346. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1347. {
  1348. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1349. }
  1350. //==========================================
  1351. // csu trigger UnlockConnectorConf
  1352. //==========================================
  1353. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1354. {
  1355. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger ReserveNowConf
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1362. {
  1363. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1365. }
  1366. //==========================================
  1367. // csu trigger DataTransferReq
  1368. //==========================================
  1369. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1370. {
  1371. sendDataTransferRequest(gun_index);
  1372. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1373. }
  1374. }
  1375. }
  1376. //==========================================
  1377. // send request routine
  1378. //==========================================
  1379. int sendAuthorizeRequest(int gun_index)
  1380. {
  1381. mtrace();
  1382. int result = FAIL;
  1383. char message[100]={0};
  1384. char guid[37];
  1385. char tempdata[65]={0};
  1386. DEBUG_INFO("sendAuthorizeRequest \n");
  1387. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1388. //Local Authorize
  1389. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1390. {
  1391. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1395. result = PASS;
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1398. authorizeRetryTimes = 0;
  1399. return result;
  1400. }
  1401. 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))||
  1402. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1403. {
  1404. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1405. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1406. {
  1407. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1408. {
  1409. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1410. }
  1411. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1412. {
  1413. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1414. }
  1415. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1421. authorizeRetryTimes = 0;
  1422. return result;
  1423. }
  1424. else
  1425. {
  1426. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1430. result = PASS;
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1433. authorizeRetryTimes = 0;
  1434. return result;
  1435. }
  1436. }
  1437. //initailize struct Authorize
  1438. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1439. //get data from shared memory
  1440. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1441. random_uuid(guid);
  1442. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1443. LWS_Send(message);
  1444. sprintf(tempdata, "Authorize,%d", gun_index);
  1445. if(hashmap_operation(0, guid, tempdata) == 1)
  1446. {
  1447. result = PASS;
  1448. DEBUG_ERROR("Authorize mapItem pass\n");
  1449. }
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1451. return result;
  1452. }
  1453. int sendBootNotificationRequest(void)
  1454. {
  1455. mtrace();
  1456. int result = FAIL;
  1457. char message[500]={0}, payload[700]={0};
  1458. char guid[37]={0};
  1459. char tempdata[65]={0};
  1460. int IsGunCharging = FALSE;
  1461. //check Transaction active
  1462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1463. {
  1464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1465. {
  1466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1467. {
  1468. IsGunCharging = TRUE;
  1469. }
  1470. }
  1471. for (int index = 0; index < CCS_QUANTITY; index++)
  1472. {
  1473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1474. {
  1475. IsGunCharging = TRUE;
  1476. }
  1477. }
  1478. for (int index = 0; index < GB_QUANTITY; index++)
  1479. {
  1480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1481. {
  1482. IsGunCharging = TRUE;
  1483. }
  1484. }
  1485. }
  1486. else
  1487. {
  1488. for (int index = 0; index < AC_QUANTITY; index++)
  1489. {
  1490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1491. {
  1492. IsGunCharging = TRUE;
  1493. }
  1494. }
  1495. }
  1496. if(IsGunCharging == TRUE)
  1497. {
  1498. server_sign = TRUE;
  1499. return result;
  1500. }
  1501. // Fill BootNotification fields
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1503. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1504. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1505. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1506. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1507. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1508. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1509. #if 0
  1510. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1511. ShmOCPP16Data->ChargeBoxId
  1512. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1513. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1514. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1515. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1516. ,ShmOCPP16Data->BootNotification.CpIccid
  1517. ,ShmOCPP16Data->BootNotification.CpImsi
  1518. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1519. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1520. #endif
  1521. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1522. ShmOCPP16Data->ChargeBoxId
  1523. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1524. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1525. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1526. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1527. ,ShmOCPP16Data->BootNotification.CpIccid
  1528. ,ShmOCPP16Data->BootNotification.CpImsi);
  1529. random_uuid(guid);
  1530. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1531. LWS_Send(message);
  1532. sprintf(tempdata, "BootNotification,0");
  1533. 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*/)
  1534. {
  1535. result = PASS;
  1536. }
  1537. memset(queuedata, 0, sizeof(queuedata));
  1538. strcpy(queuedata,message);
  1539. return result;
  1540. }
  1541. int sendDataTransferRequest(int gun_index)
  1542. {
  1543. mtrace();
  1544. char message[1000]={0};
  1545. char guid[37]={0};
  1546. char tempdata[65]={0};
  1547. int result = FAIL;
  1548. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1549. random_uuid(guid);
  1550. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1551. MESSAGE_TYPE_CALL,
  1552. guid,
  1553. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1554. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1555. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1556. LWS_Send(message);
  1557. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1558. 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*/)
  1559. {
  1560. result = PASS;
  1561. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1562. }
  1563. return result;
  1564. }
  1565. int sendDiagnosticsStatusNotificationRequest(char *status)
  1566. {
  1567. mtrace();
  1568. int result = FAIL;
  1569. char message[110]={0};
  1570. char guid[37]={0};
  1571. char tempdata[65]={0};
  1572. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1573. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1574. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1575. random_uuid(guid);
  1576. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1577. LWS_Send(message);
  1578. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1579. if(hashmap_operation(0, guid, tempdata) == 1)
  1580. {
  1581. result = PASS;
  1582. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1583. }
  1584. //#ifdef SystemLogMessage
  1585. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1586. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1587. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1588. //#endif
  1589. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1590. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1591. //record status
  1592. if(strcmp(status,"Idle")==0)
  1593. {
  1594. DiagnosticsStatusNotificationStatus = 0;
  1595. }
  1596. else if(strcmp(status,"Uploaded")==0)
  1597. {
  1598. DiagnosticsStatusNotificationStatus = 1;
  1599. }
  1600. else if(strcmp(status,"UploadFailed")==0)
  1601. {
  1602. DiagnosticsStatusNotificationStatus = 2;
  1603. }
  1604. else if(strcmp(status,"Uploading")==0)
  1605. {
  1606. DiagnosticsStatusNotificationStatus = 3;
  1607. }
  1608. return result;
  1609. }
  1610. int sendFirmwareStatusNotificationRequest(char *status)
  1611. {
  1612. mtrace();
  1613. int result = FAIL;
  1614. char message[110]={0};
  1615. char guid[37]={0};
  1616. char tempdata[65]={0};
  1617. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1618. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1619. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1620. random_uuid(guid);
  1621. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1622. LWS_Send(message);
  1623. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1624. 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*/)
  1625. {
  1626. result = PASS;
  1627. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1628. }
  1629. //#ifdef SystemLogMessage
  1630. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1631. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1632. //#endif
  1633. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1634. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1635. //record status
  1636. if(strcmp(status,"Downloaded")==0)
  1637. {
  1638. FirmwareStatusNotificationStatus = 0;
  1639. }
  1640. else if(strcmp(status,"DownloadFailed")==0)
  1641. {
  1642. FirmwareStatusNotificationStatus = 1;
  1643. }
  1644. else if(strcmp(status,"Downloading")==0)
  1645. {
  1646. FirmwareStatusNotificationStatus = 2;
  1647. }
  1648. else if(strcmp(status,"Idle")==0)
  1649. {
  1650. FirmwareStatusNotificationStatus = 3;
  1651. }
  1652. else if(strcmp(status,"InstallationFailed")==0)
  1653. {
  1654. FirmwareStatusNotificationStatus = 4;
  1655. }
  1656. else if(strcmp(status,"Installing")==0)
  1657. {
  1658. FirmwareStatusNotificationStatus = 5;
  1659. }
  1660. else if(strcmp(status,"Installed")==0)
  1661. {
  1662. FirmwareStatusNotificationStatus = 6;
  1663. }
  1664. return result;
  1665. }
  1666. int sendHeartbeatRequest(int gun_index)
  1667. {
  1668. mtrace();
  1669. int result = FAIL;
  1670. char message[80]={0};
  1671. char guid[37]={0};
  1672. char tempdata[65]={0};
  1673. random_uuid(guid);
  1674. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1675. , MESSAGE_TYPE_CALL
  1676. , guid );
  1677. LWS_Send(message);
  1678. sprintf(tempdata, "Heartbeat,%d", 0);
  1679. if(hashmap_operation(0, 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*/)
  1680. {
  1681. result = PASS;
  1682. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1683. }
  1684. return result;
  1685. }
  1686. int sendStartTransactionRequest(int gun_index)
  1687. {
  1688. mtrace();
  1689. int result = FAIL;
  1690. char message[250]={0};
  1691. char guid[37]={0};
  1692. struct timeval tmnow;
  1693. struct tm *tm;
  1694. char buf[28];//, usec_buf[6];
  1695. char tempdata[65]={0};
  1696. DEBUG_INFO("sendStartTransactionRequest...");
  1697. gettimeofday(&tmnow, NULL);
  1698. time_t t;
  1699. t = time(NULL);
  1700. /*UTC time and date*/
  1701. tm = gmtime(&t);
  1702. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1703. #if 0 // remove temporally
  1704. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1705. strcat(buf,".");
  1706. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1707. strcat(buf,usec_buf);
  1708. #endif
  1709. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1710. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1711. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1712. // clear StartTransaction Response
  1713. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1714. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1715. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1716. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1718. {
  1719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1720. {
  1721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1722. {
  1723. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1724. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1725. }
  1726. }
  1727. for (int index = 0; index < CCS_QUANTITY; index++)
  1728. {
  1729. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1730. {
  1731. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1732. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1733. }
  1734. }
  1735. for (int index = 0; index < GB_QUANTITY; index++)
  1736. {
  1737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1738. {
  1739. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1740. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1741. }
  1742. }
  1743. }
  1744. else
  1745. {
  1746. for (int index = 0; index < AC_QUANTITY; index++)
  1747. {
  1748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1749. {
  1750. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1751. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1752. }
  1753. }
  1754. }//END OF ELSE
  1755. random_uuid(guid);
  1756. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1757. , MESSAGE_TYPE_CALL
  1758. , guid
  1759. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1760. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1761. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1762. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1763. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1764. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1765. 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*/)
  1766. {
  1767. result = PASS;
  1768. }
  1769. strcpy(queuedata, message);
  1770. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1771. if(GetTransactionQueueNum() == 1)
  1772. {
  1773. LWS_Send(message);
  1774. }
  1775. #if 0
  1776. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1777. 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*/)
  1778. {
  1779. result = PASS;
  1780. }
  1781. strcpy(queuedata, message);
  1782. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1783. #endif
  1784. //#ifdef SystemLogMessage
  1785. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1786. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1787. //#endif
  1788. return result;
  1789. }
  1790. int sendStatusNotificationRequest(int gun_index)
  1791. {
  1792. mtrace();
  1793. int result = FAIL;
  1794. char message[600]={0};
  1795. char guid[37];
  1796. int currentStatus = 0;
  1797. struct timeval tmnow;
  1798. struct tm *tm;
  1799. char buf[28];//, usec_buf[6];
  1800. char tempdata[65]={0};
  1801. gettimeofday(&tmnow, NULL);
  1802. time_t t;
  1803. t = time(NULL);
  1804. /*UTC time and date*/
  1805. tm = gmtime(&t);
  1806. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1807. #if 0 // remove temporally
  1808. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1809. strcat(buf,".");
  1810. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1811. strcat(buf,usec_buf);
  1812. #endif
  1813. printf("%s",buf);
  1814. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1815. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1816. // it's option
  1817. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1818. /*
  1819. enum _SYSTEM_STATUS
  1820. {
  1821. S_BOOTING = 0,
  1822. S_IDLE, = 1
  1823. S_AUTHORIZING, =2
  1824. S_REASSIGN_CHECK, =3
  1825. S_REASSIGN, =4
  1826. S_PRECHARGE, =5
  1827. S_PREPARING_FOR_EV, =6
  1828. S_PREPARING_FOR_EVSE, =7
  1829. S_CHARGING, =8
  1830. S_TERMINATING, =9
  1831. S_COMPLETE, =10
  1832. S_ALARM, =11
  1833. S_FAULT =12
  1834. }
  1835. */
  1836. //check Transaction active
  1837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1838. {
  1839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1840. {
  1841. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1842. {
  1843. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1844. {
  1845. currentStatus = 1; //OCPP Status: Preparing
  1846. }
  1847. else
  1848. {
  1849. currentStatus = 0; //OCPP Status: Available
  1850. }
  1851. }
  1852. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1853. {
  1854. currentStatus = 1; //OCPP Status: Preparing
  1855. }
  1856. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1857. {
  1858. currentStatus = 2; //OCPP Status: Charging
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1861. {
  1862. currentStatus = 5; //OCPP Status: Finishing
  1863. }
  1864. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1865. {
  1866. currentStatus = 4; //OCPP Status: SuspendedEV
  1867. }
  1868. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((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
  1869. {
  1870. currentStatus = 7; //OCPP Status: Unavailable
  1871. }
  1872. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1873. {
  1874. currentStatus = 8; //OCPP Status: Faulted
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1877. {
  1878. currentStatus = 6; //OCPP Status: Reserved
  1879. }
  1880. }//end of for CHAdeMO_QUANTITY
  1881. for (int index = 0; index < CCS_QUANTITY; index++)
  1882. {
  1883. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1884. {
  1885. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1886. {
  1887. currentStatus = 1; //OCPP Status: Preparing
  1888. }
  1889. else
  1890. {
  1891. currentStatus = 0; //OCPP Status: Available
  1892. }
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1895. {
  1896. currentStatus = 1; //OCPP Status: Preparing
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1899. {
  1900. currentStatus = 2; //OCPP Status: Charging
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1903. {
  1904. currentStatus = 5; //OCPP Status: Finishing
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //S_TERMINATING ---> SuspendedEV
  1907. {
  1908. currentStatus = 4; //OCPP Status: SuspendedEV
  1909. }
  1910. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((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
  1911. {
  1912. currentStatus = 7; //OCPP Status : Unavailable
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM ,S_FAULT ---> Faulted
  1915. {
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. currentStatus = 6; //OCPP Status: Reserved
  1921. }
  1922. }
  1923. for (int index = 0; index < GB_QUANTITY; index++)
  1924. {
  1925. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1926. {
  1927. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1928. {
  1929. currentStatus = 1; //OCPP Status: Preparing
  1930. }
  1931. else
  1932. {
  1933. currentStatus = 0; //OCPP Status: Available
  1934. }
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1937. {
  1938. currentStatus = 1; //OCPP Status: Preparing
  1939. }
  1940. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1941. {
  1942. currentStatus = 2; //OCPP Status: Charging
  1943. }
  1944. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1945. {
  1946. currentStatus = 5; //OCPP Status: Finishing
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1949. {
  1950. currentStatus = 4; //OCPP Status: SuspendedEV
  1951. }
  1952. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((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
  1953. {
  1954. currentStatus = 7; //OCPP Status: Unavailable
  1955. }
  1956. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) )) //S_ALARM ,S_FAULT ---> Faulted
  1957. {
  1958. currentStatus = 8; //OCPP Status: Faulted
  1959. }
  1960. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1961. {
  1962. currentStatus = 6; //OCPP Status: Reserved
  1963. }
  1964. }
  1965. }
  1966. else
  1967. {
  1968. for (int index = 0; index < AC_QUANTITY; index++)
  1969. {
  1970. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1971. {
  1972. 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))
  1973. {
  1974. currentStatus = 1; //OCPP Status: Preparing
  1975. }
  1976. else
  1977. {
  1978. currentStatus = 0; //OCPP Status: Available
  1979. }
  1980. }
  1981. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1982. {
  1983. currentStatus = 1; //OCPP Status: Preparing
  1984. }
  1985. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1986. {
  1987. currentStatus = 2; //OCPP Status: Charging
  1988. }
  1989. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1990. {
  1991. currentStatus = 5; //OCPP Status: Finishing
  1992. }
  1993. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1994. {
  1995. currentStatus = 4; //OCPP Status: SuspendedEV
  1996. }
  1997. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((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
  1998. {
  1999. currentStatus = 7; //OCPP Status: Unavailable
  2000. }
  2001. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  2002. {
  2003. currentStatus = 8; //OCPP Status: Faulted
  2004. }
  2005. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2006. {
  2007. currentStatus = 6; //OCPP Status: Reserved
  2008. }
  2009. }//end of for AC_QUANTITY
  2010. }//END OF ELSE
  2011. //it's option
  2012. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2013. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2014. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2015. random_uuid(guid);
  2016. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2017. , MESSAGE_TYPE_CALL
  2018. , guid
  2019. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2020. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2021. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2022. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2023. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2024. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2025. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2026. LWS_Send(message);
  2027. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2028. 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*/)
  2029. {
  2030. //DEBUG_ERROR("statusNotification mapitem pass");
  2031. result = PASS;
  2032. }
  2033. return result;
  2034. }
  2035. int sendStopTransactionRequest(int gun_index)
  2036. {
  2037. mtrace();
  2038. int result = FAIL;
  2039. //char message[1500]={0};
  2040. char guid[37]={0};
  2041. char tempdata[65]={0};
  2042. //int idx_sample=0;
  2043. DEBUG_ERROR("sendStopTransactionRequest \n");
  2044. memset(queuedata, 0, sizeof(queuedata));
  2045. //ENERGY_ACTIVE_IMPORT_REGISTER
  2046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2047. {
  2048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2049. {
  2050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2051. {
  2052. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2053. }
  2054. }// END OF CHAdeMO_QUANTITY
  2055. for (int index = 0; index < CCS_QUANTITY; index++)
  2056. {
  2057. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2058. {
  2059. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2060. }
  2061. }// END OF CCS_QUANTITY
  2062. for (int index = 0; index < GB_QUANTITY; index++)
  2063. {
  2064. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2065. {
  2066. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2067. }
  2068. }// END OF GB_QUANTITY
  2069. }
  2070. else
  2071. {
  2072. for (int index = 0; index < AC_QUANTITY; index++)
  2073. {
  2074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2075. {
  2076. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2077. }
  2078. }// END OF AC_QUANTITY
  2079. }//END OF ELSE
  2080. //Stop Transaction Time
  2081. struct timeval tmnow;
  2082. struct tm *tm;
  2083. char buf[28];//, usec_buf[6];
  2084. gettimeofday(&tmnow, NULL);
  2085. time_t t;
  2086. t = time(NULL);
  2087. /*UTC time and date*/
  2088. tm = gmtime(&t);
  2089. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2091. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2092. random_uuid(guid);
  2093. /***********************************transactionData******************************************************/
  2094. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2096. //=================================
  2097. // Transaction_Begin
  2098. //=================================
  2099. // Energy.Active.Export.Interval
  2100. //idx_sample=0;
  2101. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2106. {
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2108. }
  2109. else
  2110. {
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2112. }
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2115. //=================================
  2116. // Transaction_End
  2117. //=================================
  2118. //Current.Export
  2119. //idx_sample=1;
  2120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2121. {
  2122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2123. {
  2124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2125. {
  2126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2127. }
  2128. }
  2129. for (int index = 0; index < CCS_QUANTITY; index++)
  2130. {
  2131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2132. {
  2133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2134. }
  2135. }
  2136. for (int index = 0; index < GB_QUANTITY; index++)
  2137. {
  2138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2139. {
  2140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2141. }
  2142. }
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2144. }
  2145. else
  2146. {
  2147. for (int index = 0; index < AC_QUANTITY; index++)
  2148. {
  2149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2150. {
  2151. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2152. }
  2153. }
  2154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2155. }// END FOR AC ELSE
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2159. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2162. //Energy.Active.Export.Interval
  2163. //idx_sample=2;
  2164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2165. {
  2166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2167. {
  2168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2169. {
  2170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2171. }
  2172. }
  2173. for (int index = 0; index < CCS_QUANTITY; index++)
  2174. {
  2175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2176. {
  2177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2178. }
  2179. }
  2180. for (int index = 0; index < GB_QUANTITY; index++)
  2181. {
  2182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2183. {
  2184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2185. }
  2186. }
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2188. }
  2189. else
  2190. {
  2191. for (int index = 0; index < AC_QUANTITY; index++)
  2192. {
  2193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2194. {
  2195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2196. }
  2197. }
  2198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2199. }// END FOR AC ELSE
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2203. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2206. //Power.Active.Export
  2207. //idx_sample=3;
  2208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2209. {
  2210. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2213. {
  2214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2215. }
  2216. }
  2217. for (int index = 0; index < CCS_QUANTITY; index++)
  2218. {
  2219. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2220. {
  2221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2222. }
  2223. }
  2224. for (int index = 0; index < GB_QUANTITY; index++)
  2225. {
  2226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2227. {
  2228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2229. }
  2230. }
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2232. }
  2233. else
  2234. {
  2235. for (int index = 0; index < AC_QUANTITY; index++)
  2236. {
  2237. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2238. {
  2239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2240. }
  2241. }
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2243. }// END FOR AC ELSE
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2247. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2250. //Voltage
  2251. //idx_sample=4;
  2252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2253. {
  2254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2255. {
  2256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2257. {
  2258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2259. }
  2260. }
  2261. for (int index = 0; index < CCS_QUANTITY; index++)
  2262. {
  2263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2264. {
  2265. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2266. }
  2267. }
  2268. for (int index = 0; index < GB_QUANTITY; index++)
  2269. {
  2270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2271. {
  2272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2273. }
  2274. }
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2276. }
  2277. else
  2278. {
  2279. for (int index = 0; index < AC_QUANTITY; index++)
  2280. {
  2281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2282. {
  2283. 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
  2284. }
  2285. }
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2287. }// END FOR AC ELSE
  2288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2291. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2294. //SoC
  2295. //idx_sample=5;
  2296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2297. {
  2298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2299. {
  2300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2301. {
  2302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2303. }
  2304. }
  2305. for (int index = 0; index < CCS_QUANTITY; index++)
  2306. {
  2307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2308. {
  2309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2310. }
  2311. }
  2312. for (int index = 0; index < GB_QUANTITY; index++)
  2313. {
  2314. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2315. {
  2316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2317. }
  2318. }
  2319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2325. } // END FOR DC CASE
  2326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2327. {
  2328. sprintf(queuedata,"[%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\"}]}]}]"
  2329. ,MESSAGE_TYPE_CALL
  2330. ,guid
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2336. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2379. );
  2380. }
  2381. else
  2382. {
  2383. sprintf(queuedata,"[%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\"}]}]}]"
  2384. ,MESSAGE_TYPE_CALL
  2385. ,guid
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2391. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2427. );
  2428. }
  2429. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2430. if(hashmap_operation(0, guid, tempdata) == 1)
  2431. {
  2432. result = PASS;
  2433. DEBUG_INFO("StopTransaction mapitem pass\n");
  2434. }
  2435. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2436. if(GetTransactionQueueNum() == 1)
  2437. {
  2438. LWS_Send(queuedata);
  2439. }
  2440. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2441. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2442. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2443. {
  2444. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2445. }
  2446. #if 0
  2447. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2448. if(hashmap_operation(0, guid, tempdata) == 1)
  2449. {
  2450. result = PASS;
  2451. DEBUG_INFO("StopTransaction mapitem pass\n");
  2452. }
  2453. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2454. #endif
  2455. //for test
  2456. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2457. return result;
  2458. }
  2459. int sendMeterValuesRequest(int gun_index)
  2460. {
  2461. mtrace();
  2462. int result = FAIL;
  2463. // char message[1500]={0};
  2464. char guid[37]={0};
  2465. //int idx_sample=0;
  2466. //int length = 0;
  2467. char tempdata[65]={0};
  2468. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2469. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2470. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2471. {
  2472. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2473. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2474. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2475. return result;
  2476. }
  2477. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2478. {
  2479. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2480. }
  2481. memset(queuedata, 0, sizeof(queuedata));
  2482. //set value
  2483. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2484. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2485. random_uuid(guid);
  2486. //UTC Date time
  2487. struct timeval tmnow;
  2488. struct tm *tm;
  2489. char buf[28];//, usec_buf[6];
  2490. gettimeofday(&tmnow, NULL);
  2491. time_t t;
  2492. t = time(NULL);
  2493. /*UTC time and date*/
  2494. tm = gmtime(&t);
  2495. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2497. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2498. //idx_sample=0;
  2499. //********************************(1)Current.Export************************************************/
  2500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2501. {
  2502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2503. {
  2504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2505. {
  2506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2507. }
  2508. }
  2509. for (int index = 0; index < CCS_QUANTITY; index++)
  2510. {
  2511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2512. {
  2513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2514. }
  2515. }
  2516. for (int index = 0; index < GB_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2524. }
  2525. else
  2526. {
  2527. for (int index = 0; index < AC_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2532. }
  2533. }
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2535. }// END FOR AC ELSE
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2539. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2542. //idx_sample=1;
  2543. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2545. {
  2546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2551. }
  2552. }
  2553. for (int index = 0; index < CCS_QUANTITY; index++)
  2554. {
  2555. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2557. {
  2558. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2560. }
  2561. }
  2562. for (int index = 0; index < GB_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2565. {
  2566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2567. }
  2568. }
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2570. }
  2571. else
  2572. {
  2573. for (int index = 0; index < AC_QUANTITY; index++)
  2574. {
  2575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2576. {
  2577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2578. }
  2579. }
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2581. }//END FOR AC ELSE
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2585. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2588. //idx_sample=2;
  2589. //********************************(4)Power.Active.Export************************************************/
  2590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2591. {
  2592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2595. {
  2596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2597. }
  2598. }
  2599. for (int index = 0; index < CCS_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2602. {
  2603. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2604. }
  2605. }
  2606. for (int index = 0; index < GB_QUANTITY; index++)
  2607. {
  2608. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2609. {
  2610. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2612. }
  2613. }
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2615. }
  2616. else
  2617. {
  2618. for (int index = 0; index < AC_QUANTITY; index++)
  2619. {
  2620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2621. {
  2622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2623. }
  2624. }
  2625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2626. }// END FOR AC ELSE
  2627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2630. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2633. //idx_sample=3;
  2634. //***********************************************(5)VOLTAGE******************************************************/
  2635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2636. {
  2637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2638. {
  2639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2640. {
  2641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2642. }
  2643. }
  2644. for (int index = 0; index < CCS_QUANTITY; index++)
  2645. {
  2646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2647. {
  2648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2649. }
  2650. }
  2651. for (int index = 0; index < GB_QUANTITY; index++)
  2652. {
  2653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2654. {
  2655. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2656. }
  2657. }
  2658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2659. }
  2660. else
  2661. {
  2662. for (int index = 0; index < AC_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2665. {
  2666. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2667. }
  2668. }
  2669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2670. }//END FOR AC ELSE
  2671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2674. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2678. {
  2679. //idx_sample=4;
  2680. //sampledValue = NULL;
  2681. //***********************************************(6)SOC******************************************************/
  2682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2683. {
  2684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2685. {
  2686. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2687. }
  2688. }
  2689. for (int index = 0; index < CCS_QUANTITY; index++)
  2690. {
  2691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2692. {
  2693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2694. }
  2695. }
  2696. for (int index = 0; index < GB_QUANTITY; index++)
  2697. {
  2698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2699. {
  2700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2701. }
  2702. }
  2703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2709. }
  2710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2711. {
  2712. sprintf(queuedata,"[%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\"}]}]}]"
  2713. ,MESSAGE_TYPE_CALL
  2714. ,guid
  2715. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2716. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2717. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2753. );
  2754. }
  2755. else
  2756. {
  2757. sprintf(queuedata,"[%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\"}]}]}]"
  2758. ,MESSAGE_TYPE_CALL
  2759. ,guid
  2760. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2761. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2762. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2791. );
  2792. }
  2793. // Put request guid to hash map
  2794. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2795. 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*/)
  2796. {
  2797. result = PASS;
  2798. DEBUG_INFO("MeterValues mapitem pass\n");
  2799. }
  2800. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2801. if(GetTransactionQueueNum() == 1)
  2802. {
  2803. LWS_Send(queuedata);
  2804. }
  2805. #if 0
  2806. // Put request guid to hash map
  2807. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2808. 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*/)
  2809. {
  2810. result = PASS;
  2811. DEBUG_INFO("MeterValues mapitem pass\n");
  2812. }
  2813. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2814. #endif
  2815. return result;
  2816. }
  2817. //==========================================
  2818. // send confirm routine
  2819. //==========================================
  2820. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[100]={0};
  2825. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2827. LWS_Send(message);
  2828. result = TRUE;
  2829. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2830. return result;
  2831. }
  2832. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2833. {
  2834. mtrace();
  2835. int result = FAIL;
  2836. char message[100]={0};
  2837. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2838. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2839. LWS_Send(message);
  2840. result = TRUE;
  2841. return result;
  2842. }
  2843. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2844. {
  2845. mtrace();
  2846. int result = FAIL;
  2847. char message[100]={0};
  2848. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2849. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2850. LWS_Send(message);
  2851. result = TRUE;
  2852. return result;
  2853. }
  2854. int sendClearCacheConfirmation(char *uuid,char *payload)
  2855. {
  2856. mtrace();
  2857. int result = FAIL;
  2858. char message[500]={0};
  2859. // int count = 0;
  2860. // int gun_index = 0;
  2861. // char guid[37];
  2862. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2863. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2864. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2865. LWS_Send(message);
  2866. return result;
  2867. }
  2868. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2869. {
  2870. mtrace();
  2871. int result = FAIL;
  2872. char message[500]={0};
  2873. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2874. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2875. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2876. LWS_Send(message);
  2877. return result;
  2878. }
  2879. int sendDataTransferConfirmation(char *uuid,char *payload)
  2880. {
  2881. mtrace();
  2882. char statusStr[20]={0};
  2883. char dataStr[10]={0};
  2884. char sstr[20]={0};
  2885. int c = 0;
  2886. char *loc;
  2887. int result = FAIL;
  2888. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2889. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2890. /**********************status**************************/
  2891. loc = strstr(payload, "status");
  2892. memset(sstr ,0, sizeof(sstr) );
  2893. c = 0;
  2894. while (loc[3+strlen("status")+c] != '\"')
  2895. {
  2896. sstr[c] = loc[3+strlen("status")+c];
  2897. c++;
  2898. }
  2899. sstr[c] = '\0';
  2900. strcpy(statusStr, sstr);
  2901. /**********************data**************************/
  2902. loc = strstr(payload, "data");
  2903. memset(sstr ,0, sizeof(sstr) );
  2904. c = 0;
  2905. while (loc[3+strlen("data")+c] != '\"')
  2906. {
  2907. sstr[c] = loc[3+strlen("data")+c];
  2908. c++;
  2909. }
  2910. sstr[c] = '\0';
  2911. strcpy(dataStr, sstr);
  2912. return result;
  2913. }
  2914. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2915. {
  2916. mtrace();
  2917. int result = FAIL;
  2918. char message[1000]={0};
  2919. double diff_f = 0.0;
  2920. int diff_i = 0;
  2921. int diffSeconds = 0;
  2922. struct tm tp;
  2923. int TimeZero = FALSE;
  2924. int CompositeScheduleIndex = 0;
  2925. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2926. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2927. {
  2928. TimeZero = TRUE;
  2929. }
  2930. else
  2931. {
  2932. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2933. }
  2934. if(TimeZero == FALSE)
  2935. {
  2936. tp.tm_isdst = -1;
  2937. time_t utc = mktime(&tp);
  2938. time_t t = time(NULL);
  2939. diff_f = difftime(t, utc);
  2940. diff_i = (int)diff_f;
  2941. diffSeconds = diff_i % 86400;//86400 seconds/day
  2942. }
  2943. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2944. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2945. #if 0 //remove temporally
  2946. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2947. ,MESSAGE_TYPE_CALLRESULT
  2948. ,uuid
  2949. ,payload
  2950. ,connectorIdInt
  2951. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2952. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2953. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2954. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2955. #endif
  2956. if(nPeriod == 0)
  2957. {
  2958. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2959. {
  2960. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2961. ,MESSAGE_TYPE_CALLRESULT
  2962. ,uuid
  2963. ,payload
  2964. ,connectorIdInt);
  2965. }
  2966. else
  2967. {
  2968. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2969. ,MESSAGE_TYPE_CALLRESULT
  2970. ,uuid
  2971. ,payload
  2972. ,connectorIdInt
  2973. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2974. }
  2975. }
  2976. else
  2977. {
  2978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2979. ,MESSAGE_TYPE_CALLRESULT
  2980. ,uuid
  2981. ,payload
  2982. ,connectorIdInt
  2983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2984. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2985. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2986. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2987. int len = nPeriod;
  2988. //Last Period StartPriod is less than diffSeconds
  2989. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2990. {
  2991. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2992. , 0
  2993. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2995. }
  2996. else
  2997. {
  2998. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2999. {
  3000. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  3001. {
  3002. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3003. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3004. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3005. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3006. }
  3007. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3008. {
  3009. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3010. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3011. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3012. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3013. }
  3014. }
  3015. }
  3016. sprintf(message + strlen(message), "]}}]");
  3017. }
  3018. LWS_Send(message);
  3019. result = TRUE;
  3020. return result;
  3021. }
  3022. int sendGetConfigurationConfirmation(char *uuid)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. int MaxKeySupported = 0;
  3027. int sentConfigurationNumber= 0;
  3028. int sentunConfigurationNumber= 0;
  3029. char message[4000]={0};
  3030. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3031. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3032. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3033. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3034. ,MESSAGE_TYPE_CALLRESULT
  3035. ,uuid );
  3036. //configuration key
  3037. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3038. {
  3039. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3040. {
  3041. if (sentConfigurationNumber == 0)
  3042. {
  3043. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3044. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3045. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3046. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3047. }
  3048. else
  3049. {
  3050. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3051. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3052. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3053. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3054. }
  3055. sentConfigurationNumber = sentConfigurationNumber + 1;
  3056. }
  3057. }
  3058. sprintf(message + strlen(message), "]");
  3059. if(UnknownKeynum != 0)
  3060. {
  3061. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3062. //unkown key
  3063. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3064. {
  3065. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3066. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3067. if(sentunConfigurationNumber == 0)
  3068. {
  3069. sprintf(message + strlen(message), "\"%s\""
  3070. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3071. }
  3072. else
  3073. {
  3074. sprintf(message + strlen(message), ",\"%s\""
  3075. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3076. }
  3077. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3078. }
  3079. sprintf(message + strlen(message), "]");
  3080. }
  3081. sprintf(message + strlen(message), "}]");
  3082. LWS_Send(message);
  3083. return result;
  3084. }
  3085. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3086. {
  3087. mtrace();
  3088. int result = FAIL;
  3089. char message[400]={0};
  3090. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3091. if(strcmp(payload,"")==0)
  3092. {
  3093. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3094. }
  3095. else
  3096. {
  3097. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3098. }
  3099. LWS_Send(message);
  3100. result = TRUE;
  3101. return result;
  3102. }
  3103. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3104. {
  3105. mtrace();
  3106. int result = FAIL;
  3107. char message[80]={0};
  3108. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3109. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3110. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3111. LWS_Send(message);
  3112. result = TRUE;
  3113. return result;
  3114. }
  3115. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3116. {
  3117. mtrace();
  3118. int result = FAIL;
  3119. char message[80]={0};
  3120. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3121. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3123. LWS_Send(message);
  3124. result = TRUE;
  3125. return result;
  3126. }
  3127. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3128. {
  3129. mtrace();
  3130. int result = FAIL;
  3131. char message[80]={0};
  3132. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3133. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3134. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3135. LWS_Send(message);
  3136. result = TRUE;
  3137. return result;
  3138. }
  3139. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3140. {
  3141. mtrace();
  3142. int result = FAIL;
  3143. char message[80]={0};
  3144. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3145. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3146. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3147. LWS_Send(message);
  3148. result = TRUE;
  3149. return result;
  3150. }
  3151. int sendResetConfirmation(char *uuid,char *payload)
  3152. {
  3153. mtrace();
  3154. int result = FAIL;
  3155. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3156. char message[80]={0};
  3157. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3158. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3159. LWS_Send(message);
  3160. result = TRUE;
  3161. return result;
  3162. }
  3163. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3164. {
  3165. mtrace();
  3166. int result = FAIL;
  3167. char message[500]={0};
  3168. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3169. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3175. {
  3176. mtrace();
  3177. int result = FAIL;
  3178. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3179. char message[80]={0};
  3180. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3182. LWS_Send(message);
  3183. result = TRUE;
  3184. return result;
  3185. }
  3186. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3187. {
  3188. mtrace();
  3189. int result = FAIL;
  3190. char message[80]={0};
  3191. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3192. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3193. LWS_Send(message);
  3194. result = TRUE;
  3195. return result;
  3196. }
  3197. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3198. {
  3199. mtrace();
  3200. int result = FAIL;
  3201. char message[80]={0};
  3202. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3203. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3204. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3205. LWS_Send(message);
  3206. result = TRUE;
  3207. return result;
  3208. }
  3209. int sendUpdateFirmwareConfirmation(char *uuid)
  3210. {
  3211. mtrace();
  3212. int result = FAIL;
  3213. char message[60]={0};
  3214. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3215. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3216. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3217. LWS_Send(message);
  3218. result = TRUE;
  3219. return result;
  3220. }
  3221. //==========================================
  3222. // send CallError routine
  3223. //==========================================
  3224. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3225. {
  3226. mtrace();
  3227. //int result = FAIL;
  3228. char message[220]={0};
  3229. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3230. #ifdef SystemLogMessage
  3231. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3232. uniqueId, action, errorCode, errorDescription);
  3233. #endif
  3234. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3235. LWS_Send(message);
  3236. //result = TRUE;
  3237. }
  3238. //==========================================
  3239. // Handle server request routine Start
  3240. //==========================================
  3241. #define GUN_NUM 1
  3242. int handleCancelReservationRequest(char *uuid, char *payload)
  3243. {
  3244. mtrace();
  3245. int result = FAIL;
  3246. int gunNO = 0;
  3247. int reservationIdInt =0;
  3248. char comfirmstr[20];
  3249. int c = 0;
  3250. char *loc;
  3251. char sstr[100]={0};
  3252. DEBUG_INFO("handle CancelReservationRequest\n");
  3253. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3254. c = 0;
  3255. loc = strstr(payload, "reservationId");
  3256. memset(sstr ,0, sizeof(sstr) );
  3257. while (loc[strlen("reservationId")+2+c] != '}')
  3258. {
  3259. sstr[c] = loc[strlen("reservationId")+2+c];
  3260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3261. c++;
  3262. }
  3263. sstr[c] = '\0';
  3264. reservationIdInt = atoi(sstr);
  3265. memset(comfirmstr, 0, sizeof comfirmstr);
  3266. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3267. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3268. //check Transaction active
  3269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3270. {
  3271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3272. {
  3273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3274. {
  3275. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3276. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3277. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3278. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3279. goto end;
  3280. }
  3281. }
  3282. for (int index = 0; index < CCS_QUANTITY; index++)
  3283. {
  3284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3285. {
  3286. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3287. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3288. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3289. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3290. goto end;
  3291. }
  3292. }
  3293. for (int index = 0; index < GB_QUANTITY; index++)
  3294. {
  3295. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3296. {
  3297. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3298. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3299. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3300. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3301. goto end;
  3302. }
  3303. }
  3304. }
  3305. else
  3306. {
  3307. for (int index = 0; index < AC_QUANTITY; index++)
  3308. {
  3309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3310. {
  3311. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3312. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3313. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3314. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3315. goto end;
  3316. }
  3317. }
  3318. }// END FOR AC ELSE
  3319. //The reservationId does NOT match the reservationId
  3320. sendCancelReservationConfirmation(uuid, comfirmstr);
  3321. end:
  3322. // Fill in ocpp packet uuid
  3323. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3324. return result;
  3325. }
  3326. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3327. {
  3328. mtrace();
  3329. int result = FAIL;
  3330. int gunIndex = 0;
  3331. char sstr[90]={0};
  3332. char typeStr[16]={0};
  3333. char comfirmstr[20];
  3334. int specificId = FALSE;
  3335. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3336. char *loc;
  3337. //int intervalInt = 0;
  3338. int c = 0;
  3339. /*** connectorId ****/
  3340. c = 0;
  3341. loc = strstr(payload, "connectorId");
  3342. memset(sstr ,0, sizeof(sstr) );
  3343. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3344. {
  3345. sstr[c] = loc[strlen("connectorId")+2+c];
  3346. c++;
  3347. }
  3348. sstr[c] = '\0';
  3349. gunIndex = atoi(sstr);
  3350. /***type ****/
  3351. loc = strstr(payload, "type");
  3352. memset(sstr ,0, sizeof(sstr) );
  3353. c = 0;
  3354. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3355. {
  3356. sstr[c] = loc[3+strlen("type")+c];
  3357. c++;
  3358. }
  3359. sstr[c] = '\0';
  3360. strcpy(typeStr, sstr);
  3361. if(gunIndex != 0)
  3362. {
  3363. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3364. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3365. }
  3366. else
  3367. {
  3368. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3369. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3370. }
  3371. memset(comfirmstr, 0, sizeof comfirmstr);
  3372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3373. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3374. {
  3375. specificId = TRUE;
  3376. }
  3377. if(specificId == FALSE)
  3378. goto end;
  3379. if(gunIndex != 0)
  3380. {
  3381. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3382. }
  3383. else
  3384. {
  3385. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3386. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3387. }
  3388. /*
  3389. enum SYSTEM_STATUS
  3390. {
  3391. SYS_MODE_BOOTING = 0,
  3392. SYS_MODE_IDLE = 1,
  3393. SYS_MODE_AUTHORIZING = 2,
  3394. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3395. SYS_MODE_REASSIGN = 4,
  3396. SYS_MODE_PREPARING = 5,
  3397. SYS_MODE_PREPARE_FOR_EV = 6,
  3398. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3399. SYS_MODE_CHARGING = 8,
  3400. SYS_MODE_TERMINATING = 9,
  3401. SYS_MODE_COMPLETE = 10,
  3402. SYS_MODE_ALARM = 11,
  3403. SYS_MODE_FAULT = 12,
  3404. SYS_MODE_RESERVATION = 13,
  3405. SYS_MODE_BOOKING = 14,
  3406. SYS_MODE_MAINTAIN = 15,
  3407. SYS_MODE_DEBUG = 16,
  3408. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3409. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3410. SYS_MODE_UPDATE = 19
  3411. };
  3412. */
  3413. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3414. {
  3415. //check Transaction active
  3416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3417. {
  3418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3419. {
  3420. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3421. {
  3422. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3423. {
  3424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3425. }
  3426. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3427. {
  3428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3429. }
  3430. else
  3431. {
  3432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3433. }
  3434. goto end;
  3435. }
  3436. }//END FOR CHAdeMO_QUANTITY
  3437. for (int index = 0; index < CCS_QUANTITY; index++)
  3438. {
  3439. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3440. {
  3441. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3442. {
  3443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3444. }
  3445. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3448. }
  3449. else
  3450. {
  3451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3452. }
  3453. goto end;
  3454. }
  3455. }//END FOR CCS_QUANTITY
  3456. for (int index = 0; index < GB_QUANTITY; index++)
  3457. {
  3458. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3459. {
  3460. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3461. {
  3462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3463. }
  3464. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3465. {
  3466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3467. }
  3468. else
  3469. {
  3470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3471. }
  3472. goto end;
  3473. }
  3474. }// END FOR GB_QUANTITY
  3475. }
  3476. else
  3477. {
  3478. for (int index = 0; index < AC_QUANTITY; index++)
  3479. {
  3480. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3481. {
  3482. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3483. {
  3484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3485. }
  3486. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3487. {
  3488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3489. }
  3490. else
  3491. {
  3492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3493. }
  3494. goto end;
  3495. }
  3496. }//END FOR AC_QUANTITY
  3497. }// END FOR AC ELSE
  3498. }//END FOR AvailabilityTypeStr[Inoperative]
  3499. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3500. {
  3501. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3502. //check Transaction active
  3503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3504. {
  3505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3506. {
  3507. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3508. {
  3509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3510. goto end;
  3511. }
  3512. }//END FOR CHAdeMO_QUANTITY
  3513. for (int index = 0; index < CCS_QUANTITY; index++)
  3514. {
  3515. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3516. {
  3517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3518. goto end;
  3519. }
  3520. }//END FOR CCS_QUANTITY
  3521. for (int index = 0; index < GB_QUANTITY; index++)
  3522. {
  3523. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3524. {
  3525. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3527. goto end;
  3528. }
  3529. }// END FOR GB_QUANTITY
  3530. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3531. }
  3532. else
  3533. {
  3534. for (int index = 0; index < AC_QUANTITY; index++)
  3535. {
  3536. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3537. {
  3538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3539. goto end;
  3540. }
  3541. }//END FOR CHAdeMO_QUANTITY
  3542. }//END FOR AC ELSE
  3543. }//END FOR AvailabilityTypeStr[Operative]
  3544. end:
  3545. if(gunIndex != 0)
  3546. {
  3547. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3548. }
  3549. else
  3550. {
  3551. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3552. }
  3553. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3554. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3555. return result;
  3556. }
  3557. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3558. {
  3559. mtrace();
  3560. int result = FAIL;
  3561. char sstr[100]={0};
  3562. char keystr[40]={0};
  3563. char valuestr[100]={0};
  3564. char *loc;
  3565. int c = 0;
  3566. char comfirmstr[20]={0};
  3567. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3568. /***key ****/
  3569. loc = strstr(payload, "key");
  3570. memset(sstr ,0, sizeof(sstr) );
  3571. c = 0;
  3572. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3573. {
  3574. sstr[c] = loc[3+strlen("key")+c];
  3575. c++;
  3576. }
  3577. sstr[c] = '\0';
  3578. strcpy(keystr, sstr);
  3579. //DEBUG_INFO( "keystr=%s\n",keystr);
  3580. /***value ****/
  3581. loc = strstr(payload, "value");
  3582. memset(sstr ,0, sizeof(sstr) );
  3583. c = 0;
  3584. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3585. {
  3586. sstr[c] = loc[3+strlen("value")+c];
  3587. c++;
  3588. }
  3589. sstr[c] = '\0';
  3590. strcpy(valuestr, sstr);
  3591. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3592. if((uuid==NULL) || (payload ==NULL) )
  3593. {
  3594. #ifdef Debug
  3595. DEBUG_INFO("payload is null\n");
  3596. #endif
  3597. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3598. }
  3599. else
  3600. {
  3601. int status = setKeyValue(keystr, valuestr);
  3602. switch(status)
  3603. {
  3604. case ConfigurationStatus_Accepted:
  3605. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3606. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3607. StoreConfigurationTable();
  3608. break;
  3609. case ConfigurationStatus_Rejected:
  3610. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3611. break;
  3612. case RebootRequired:
  3613. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3614. StoreConfigurationTable();
  3615. break;
  3616. case NotSupported:
  3617. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3618. break;
  3619. default:
  3620. break;
  3621. }
  3622. }
  3623. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3624. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3625. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3626. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3627. {
  3628. ChageWebSocketPingInterval(atoi(valuestr));
  3629. }
  3630. return result;
  3631. }
  3632. int handleClearCacheRequest(char *uuid, char *payload)
  3633. {
  3634. mtrace();
  3635. int result = FAIL;
  3636. char comfirmstr[20];
  3637. int fd;
  3638. char rmFileCmd[100]={0};
  3639. struct stat stats;
  3640. DEBUG_INFO("handle ClearCacheRequest\n");
  3641. stat("/Storage/OCPP", &stats);
  3642. // Check for directory existence
  3643. if (S_ISDIR(stats.st_mode) == 1)
  3644. {
  3645. //DEBUG_ERROR("\n OCPP directory exist \n");
  3646. }
  3647. else
  3648. {
  3649. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3650. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3651. system(rmFileCmd);
  3652. }
  3653. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3654. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3655. {
  3656. DEBUG_INFO("AuthorizationCache file exist.\n");
  3657. }
  3658. else
  3659. {
  3660. DEBUG_INFO("AuthorizationCache file not exist\n");
  3661. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3662. if(log == NULL)
  3663. {
  3664. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3665. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3666. goto end;
  3667. }
  3668. else
  3669. {
  3670. fclose(log);
  3671. }
  3672. }
  3673. fd = open(AuthorizationCache_JSON,O_RDWR);
  3674. if(fd < 0)
  3675. {
  3676. DEBUG_INFO("open AuthorizationCache file failed\n");
  3677. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3678. }
  3679. else
  3680. {
  3681. DEBUG_INFO("open AuthorizationCache file successful\n");
  3682. //* 清空? 件 */
  3683. ftruncate(fd,0);
  3684. //* ? 新设置? 件? 移??*/
  3685. lseek(fd,0,SEEK_SET);
  3686. close(fd);
  3687. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3688. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3689. }
  3690. end:
  3691. sendClearCacheConfirmation(uuid, comfirmstr);
  3692. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3693. return result;
  3694. }
  3695. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3696. {
  3697. mtrace();
  3698. int result = FAIL;
  3699. int resultRename;
  3700. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3701. char chargingProfilePurposeStr[26]={0};
  3702. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3703. char tempchargingProfilePurposeStr[26]={0};
  3704. char sstr[160]={0};//sstr[200]={ 0 };
  3705. char str[100]={0};
  3706. int c = 0;
  3707. //int i = 0;
  3708. //char * pch;
  3709. char *loc;
  3710. char fname[200]={0};
  3711. char comfirmstr[20]={0};
  3712. char word[1600]={0};
  3713. int clearflag = FALSE;
  3714. int chargingProfileIdIsNULL = FALSE;
  3715. int connectorIsNULL = FALSE;
  3716. int chargingProfilePurposeIsNULL = FALSE;
  3717. int stackLevelIsNULL = FALSE;
  3718. //int GotoEnd = FALSE;
  3719. FILE *fptr1, *fptr2;
  3720. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3721. int n_chargingProfile=0;
  3722. int isEmptyFile = FALSE;
  3723. char sLineWord[1600]={0};
  3724. char chargingProfiles[10][100]={0};
  3725. int ChargeProfileCount = 0;
  3726. char ch;
  3727. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3728. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3729. //***id ****/
  3730. c = 0;
  3731. loc = strstr(payload, "id");
  3732. memset(sstr ,0, sizeof(sstr) );
  3733. if(loc == NULL)
  3734. {
  3735. chargingProfileIdIsNULL = TRUE;
  3736. }
  3737. else
  3738. {
  3739. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3740. {
  3741. sstr[c] = loc[strlen("id")+2+c];
  3742. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3743. c++;
  3744. }
  3745. sstr[c] = '\0';
  3746. chargingProfileIdInt = atoi(sstr);
  3747. }
  3748. //***connectorId ****/
  3749. c=0;
  3750. loc = strstr(payload, "connectorId");
  3751. memset(sstr ,0, sizeof(sstr) );
  3752. if(loc == NULL)
  3753. {
  3754. connectorIsNULL = TRUE;
  3755. }
  3756. else
  3757. {
  3758. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3759. {
  3760. sstr[c] = loc[strlen("connectorId")+2+c];
  3761. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3762. c++;
  3763. }
  3764. sstr[c] = '\0';
  3765. connectorIdInt = atoi(sstr);
  3766. }
  3767. //***chargingProfilePurpose ****/
  3768. loc = strstr(payload, "chargingProfilePurpose");
  3769. memset(sstr ,0, sizeof(sstr) );
  3770. c = 0;
  3771. if(loc == NULL)
  3772. {
  3773. chargingProfilePurposeIsNULL = TRUE;
  3774. }
  3775. else
  3776. {
  3777. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3778. {
  3779. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3780. c++;
  3781. }
  3782. sstr[c] = '\0';
  3783. strcpy(chargingProfilePurposeStr, sstr);
  3784. }
  3785. //***stackLevel ****/
  3786. c=0;
  3787. loc = strstr(payload, "stackLevel");
  3788. memset(sstr ,0, sizeof(sstr) );
  3789. if(loc == NULL)
  3790. {
  3791. stackLevelIsNULL = TRUE;
  3792. }
  3793. else
  3794. {
  3795. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3796. {
  3797. sstr[c] = loc[strlen("stackLevel")+2+c];
  3798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3799. c++;
  3800. }
  3801. sstr[c] = '\0';
  3802. stackLevelInt = atoi(sstr);
  3803. }
  3804. if(connectorIsNULL == FALSE)
  3805. {
  3806. switch(connectorIdInt)
  3807. {
  3808. case 0:
  3809. if(chargingProfilePurposeIsNULL == TRUE)
  3810. {
  3811. int l = 0;
  3812. strcpy(fname, ChargePointMaxProfile_JSON);
  3813. if((access(fname,F_OK))!=-1)
  3814. {
  3815. strcpy(chargingProfiles[l], fname);
  3816. l = l + 1;
  3817. }
  3818. strcpy(fname, TxDefaultProfile_0_JSON);
  3819. if((access(fname,F_OK))!=-1)
  3820. {
  3821. strcpy(chargingProfiles[l], fname);
  3822. l = l + 1;
  3823. }
  3824. ChargeProfileCount = l;
  3825. }
  3826. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3827. {
  3828. strcpy(fname, ChargePointMaxProfile_JSON);
  3829. if((access(fname,F_OK))!=-1)
  3830. {
  3831. strcpy(chargingProfiles[0], fname);
  3832. ChargeProfileCount = 1;
  3833. }
  3834. }
  3835. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3836. {
  3837. strcpy(fname, TxDefaultProfile_0_JSON);
  3838. if((access(fname,F_OK))!=-1)
  3839. {
  3840. strcpy(chargingProfiles[0], fname);
  3841. ChargeProfileCount = 1;
  3842. }
  3843. }
  3844. break;
  3845. default:
  3846. if(chargingProfilePurposeIsNULL == TRUE)
  3847. {
  3848. int m = 0;
  3849. memset(fname, 0, sizeof fname);
  3850. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3851. if((access(fname,F_OK))!=-1)
  3852. {
  3853. strcpy(chargingProfiles[m], fname);
  3854. m = m + 1;
  3855. }
  3856. memset(fname, 0, sizeof fname);
  3857. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3858. if((access(fname,F_OK))!=-1)
  3859. {
  3860. strcpy(chargingProfiles[m], fname);
  3861. m = m + 1;
  3862. }
  3863. ChargeProfileCount = m;
  3864. }
  3865. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3866. {
  3867. //strcpy(fname, TxDefaultProfile_1_JSON);
  3868. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3869. if((access(fname,F_OK))!=-1)
  3870. {
  3871. strcpy(chargingProfiles[0], fname);
  3872. ChargeProfileCount = 1;
  3873. }
  3874. }
  3875. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3876. {
  3877. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3878. if((access(fname,F_OK))!=-1)
  3879. {
  3880. strcpy(chargingProfiles[0], fname);
  3881. ChargeProfileCount = 1;
  3882. }
  3883. //strcpy(fname, TxProfile_1_JSON);
  3884. }
  3885. //strcpy(fname, ChargePointMaxProfile_JSON );
  3886. break;
  3887. }
  3888. }
  3889. else // Check all Charging Profiles
  3890. {
  3891. int i = 0;
  3892. char fnametemp[200]={0};
  3893. ChargeProfileCount = 0;
  3894. //Check ChargePointMaxProfile.json exit
  3895. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3896. {
  3897. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3898. i = i + 1;
  3899. }
  3900. //Check TxDefaultProfile_0.json exit
  3901. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3902. {
  3903. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3904. i = i + 1;
  3905. }
  3906. //Check TxDefaultProfile_%d.json
  3907. for(int j=1; j <= gunTotalNumber; j++)
  3908. {
  3909. memset(fnametemp, 0, sizeof fnametemp);
  3910. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3911. if((access(fnametemp,F_OK))!=-1)
  3912. {
  3913. strcpy(chargingProfiles[i], fnametemp);
  3914. i = i + 1;
  3915. }
  3916. }
  3917. //Check TxProfile_%d.json
  3918. for(int j=1; j <= gunTotalNumber; j++)
  3919. {
  3920. memset(fnametemp, 0, sizeof fnametemp);
  3921. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3922. if((access(fnametemp,F_OK))!=-1)
  3923. {
  3924. strcpy(chargingProfiles[i], fnametemp);
  3925. i = i + 1;
  3926. }
  3927. }
  3928. ChargeProfileCount = i;
  3929. }// End connectorIsNULL is TRUE
  3930. if(ChargeProfileCount == 0)
  3931. {
  3932. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3933. goto end;
  3934. }
  3935. #if 0
  3936. fptr1 = fopen(fname, "r");
  3937. if (!fptr1)
  3938. {
  3939. //file not exist
  3940. DEBUG_INFO("Unable to open the input file!!\n");
  3941. fptr1 = fopen(fname, "w+");
  3942. }
  3943. fclose(fptr1);
  3944. #endif
  3945. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3946. {
  3947. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3948. goto end;
  3949. }
  3950. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3951. {
  3952. memset(str, 0, sizeof str);
  3953. // clear temp file
  3954. sprintf(str,"rm -f %s",temp);
  3955. system(str);
  3956. for(int k=0; k < ChargeProfileCount; k++)
  3957. {
  3958. memset(str, 0, sizeof str);
  3959. //clear file in C
  3960. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3961. system(str);
  3962. }
  3963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3964. goto end;
  3965. }
  3966. else if(connectorIsNULL == TRUE)
  3967. {
  3968. for(int k=0; k < ChargeProfileCount; k++)
  3969. {
  3970. fptr1 = fopen(chargingProfiles[k], "r");
  3971. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3972. //Check Charging Profile Count
  3973. while(fscanf(fptr1, "%s", word) != EOF)
  3974. {
  3975. //DEBUG_INFO("word=%s\n",word);
  3976. if(strstr(word, "chargingProfileId")!= NULL)
  3977. {
  3978. //DEBUG_INFO("test chargingProfileId \n");
  3979. n_chargingProfile = n_chargingProfile + 1;
  3980. //DEBUG_INFO("chargingProfileId Found\n");
  3981. }
  3982. }
  3983. rewind(fptr1);
  3984. //search Charging Profile Element
  3985. //int i= 0;
  3986. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3987. {
  3988. //------------------------tempconnectorIdInt------------------------//
  3989. loc = strstr(sLineWord, "connectorId");
  3990. c = 0;
  3991. memset(sstr ,0, sizeof(sstr) );
  3992. while (loc[strlen("connectorId")+2+c] != ',')
  3993. {
  3994. sstr[c] = loc[strlen("connectorId")+2+c];
  3995. c++;
  3996. }
  3997. sstr[c] = '\0';
  3998. tempconnectorIdInt = atoi(sstr);
  3999. printf("file's gun number is %d\n", tempconnectorIdInt);
  4000. //--------------------------chargingProfileId--------------------//
  4001. c = 0;
  4002. loc = strstr(sLineWord, "chargingProfileId");
  4003. memset(sstr ,0, sizeof(sstr) );
  4004. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4005. {
  4006. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4008. c++;
  4009. }
  4010. sstr[c] = '\0';
  4011. tempchargingProfileIdInt = atoi(sstr);
  4012. //stackLevel
  4013. c = 0;
  4014. loc = strstr(sLineWord, "stackLevel");
  4015. memset(sstr ,0, sizeof(sstr) );
  4016. while (loc[strlen("stackLevel")+2+c] != ',')
  4017. {
  4018. sstr[c] = loc[strlen("stackLevel")+2+c];
  4019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4020. c++;
  4021. }
  4022. sstr[c] = '\0';
  4023. tempstackLevelInt = atoi(sstr);
  4024. c = 0;
  4025. loc = strstr(sLineWord, "chargingProfilePurpose");
  4026. memset(sstr ,0, sizeof(sstr) );
  4027. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4028. {
  4029. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4030. c++;
  4031. }
  4032. sstr[c] = '\0';
  4033. strcpy(tempchargingProfilePurposeStr, sstr);
  4034. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4035. {
  4036. //------- not write to fptr2-------//
  4037. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4038. //clearflag = TRUE;
  4039. }
  4040. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4041. {
  4042. //------- not write to fptr2-------//
  4043. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4044. }
  4045. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4046. {
  4047. //------- not write to fptr2-------//
  4048. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4049. }
  4050. else
  4051. {
  4052. fprintf(fptr2, sLineWord);//writing data into file
  4053. }
  4054. memset(sLineWord, 0, sizeof sLineWord);
  4055. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4056. if(clearflag == TRUE)
  4057. {
  4058. fclose(fptr1);
  4059. fclose(fptr2);
  4060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4061. system(str);
  4062. // clear temp file
  4063. sprintf(str,"rm -f %s",temp);
  4064. system(str);
  4065. }
  4066. else
  4067. {
  4068. fclose(fptr1);
  4069. fclose(fptr2);
  4070. memset(str, 0, sizeof str);
  4071. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4072. system(str);
  4073. resultRename = rename(temp, chargingProfiles[k]);
  4074. if(resultRename == 0)
  4075. {
  4076. DEBUG_INFO("File ChargingProfile renamed successfully");
  4077. }
  4078. else
  4079. {
  4080. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4081. }
  4082. if(comfirmstr[0]== 0)
  4083. {
  4084. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4085. }
  4086. //Check chargingProfile is empty file
  4087. /*------ Read the file ----------------*/
  4088. fptr1=fopen(chargingProfiles[k],"r");
  4089. ch=fgetc(fptr1);
  4090. rewind(fptr1);
  4091. memset(sLineWord, 0, sizeof sLineWord);
  4092. if(ch!=EOF)
  4093. {
  4094. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4095. {
  4096. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4097. if(sLineWord[0]=='\0')
  4098. {
  4099. isEmptyFile = TRUE;
  4100. break;
  4101. }
  4102. else
  4103. {
  4104. isEmptyFile = FALSE;
  4105. break;
  4106. }
  4107. }
  4108. }
  4109. fclose(fptr1);
  4110. if(isEmptyFile == TRUE)
  4111. {
  4112. memset(str, 0, sizeof str);
  4113. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4114. system(str);
  4115. }
  4116. }
  4117. }// End of while(int k=0; k < ChargePointCount; k++)
  4118. }
  4119. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4120. {
  4121. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4122. for(int k=0; k < ChargeProfileCount; k++)
  4123. {
  4124. fptr1 = fopen(chargingProfiles[k], "r");
  4125. fptr2 = fopen(temp, "w+");
  4126. //Check Charging Profile Count
  4127. while(fscanf(fptr1, "%s", word) != EOF)
  4128. {
  4129. //DEBUG_INFO("word=%s\n",word);
  4130. if(strstr(word, "chargingProfileId")!= NULL)
  4131. {
  4132. //DEBUG_INFO("test chargingProfileId \n");
  4133. n_chargingProfile = n_chargingProfile + 1;
  4134. //DEBUG_INFO("chargingProfileId Found\n");
  4135. }
  4136. }
  4137. rewind(fptr1);
  4138. //search Charging Profile Element
  4139. //int i= 0;
  4140. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4141. {
  4142. //*************************tempconnectorIdInt*********************************/
  4143. loc = strstr(sLineWord, "connectorId");
  4144. c = 0;
  4145. memset(sstr ,0, sizeof(sstr) );
  4146. while (loc[strlen("connectorId")+2+c] != ',')
  4147. {
  4148. sstr[c] = loc[strlen("connectorId")+2+c];
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. tempconnectorIdInt = atoi(sstr);
  4153. //chargingProfileId
  4154. c = 0;
  4155. loc = strstr(sLineWord, "chargingProfileId");
  4156. memset(sstr ,0, sizeof(sstr) );
  4157. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4158. {
  4159. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4161. c++;
  4162. }
  4163. sstr[c] = '\0';
  4164. tempchargingProfileIdInt = atoi(sstr);
  4165. //stackLevel
  4166. c = 0;
  4167. loc = strstr(sLineWord, "stackLevel");
  4168. memset(sstr ,0, sizeof(sstr) );
  4169. while (loc[strlen("stackLevel")+2+c] != ',')
  4170. {
  4171. sstr[c] = loc[strlen("stackLevel")+2+c];
  4172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4173. c++;
  4174. }
  4175. sstr[c] = '\0';
  4176. tempstackLevelInt = atoi(sstr);
  4177. c = 0;
  4178. loc = strstr(sLineWord, "chargingProfilePurpose");
  4179. memset(sstr ,0, sizeof(sstr) );
  4180. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4181. {
  4182. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4183. c++;
  4184. }
  4185. sstr[c] = '\0';
  4186. strcpy(tempchargingProfilePurposeStr, sstr);
  4187. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4188. {
  4189. //------- not write to fptr2-------//
  4190. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4191. //clearflag = TRUE;
  4192. }
  4193. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4194. {
  4195. //------- not write to fptr2-------//
  4196. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4197. }
  4198. else if(stackLevelIsNULL == TRUE)
  4199. {
  4200. //Clear Whole File
  4201. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4202. clearflag = TRUE;
  4203. break;
  4204. }
  4205. else
  4206. {
  4207. fprintf(fptr2, sLineWord);//writing data into file
  4208. }
  4209. memset(sLineWord, 0, sizeof sLineWord);
  4210. }
  4211. if(clearflag == TRUE)
  4212. {
  4213. fclose(fptr1);
  4214. fclose(fptr2);
  4215. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4216. system(str);
  4217. // clear temp file
  4218. sprintf(str,"rm -f %s",temp);
  4219. system(str);
  4220. }
  4221. else
  4222. {
  4223. fclose(fptr1);
  4224. fclose(fptr2);
  4225. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4226. system(str);
  4227. resultRename = rename(temp, chargingProfiles[k]);
  4228. if(resultRename == 0)
  4229. {
  4230. DEBUG_INFO("File ChargingProfile renamed successfully");
  4231. }
  4232. else
  4233. {
  4234. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4235. }
  4236. if(comfirmstr[0]== 0)
  4237. {
  4238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4239. }
  4240. //Check chargingProfile is empty file
  4241. /*------ Read the file ----------------*/
  4242. fptr1=fopen(chargingProfiles[k],"r");
  4243. ch=fgetc(fptr1);
  4244. rewind(fptr1);
  4245. memset(sLineWord, 0, sizeof sLineWord);
  4246. if(ch!=EOF)
  4247. {
  4248. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4249. {
  4250. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4251. if(sLineWord[0]=='\0')
  4252. {
  4253. isEmptyFile = TRUE;
  4254. break;
  4255. }
  4256. else
  4257. {
  4258. isEmptyFile = FALSE;
  4259. break;
  4260. }
  4261. }
  4262. }
  4263. fclose(fptr1);
  4264. if(isEmptyFile == TRUE)
  4265. {
  4266. memset(str, 0, sizeof str);
  4267. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4268. system(str);
  4269. }
  4270. /*------- End of reading ---------------*/
  4271. }
  4272. } // while(int k=0; k < ChargeProfileCount; k++)
  4273. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4274. end:
  4275. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4276. return result;
  4277. }
  4278. int handleDataTransferRequest(char *uuid, char *payload)
  4279. {
  4280. mtrace();
  4281. int result = FAIL;
  4282. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4283. char tempvendorId[255]={0};
  4284. char tempmessageId[50]={0};
  4285. char tempdata[50]={0};
  4286. char sstr[160]={0};//sstr[200]={ 0 };
  4287. char message[80]={0};
  4288. int c = 0;
  4289. char *loc;
  4290. DEBUG_INFO("handle DataTransferRequest\n");
  4291. if((uuid != NULL) && (payload != NULL))
  4292. {
  4293. //===============================
  4294. // vendorId
  4295. //===============================
  4296. c = 0;
  4297. loc = strstr(payload, "vendorId");
  4298. while (loc[strlen("vendorId")+3+c] != '\"')
  4299. {
  4300. sstr[c] = loc[strlen("vendorId")+3+c];
  4301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4302. c++;
  4303. }
  4304. sstr[c] = '\0';
  4305. strcpy(tempvendorId,sstr);
  4306. //===============================
  4307. // messageId
  4308. //===============================
  4309. memset(sstr ,0, sizeof(sstr) );
  4310. c = 0;
  4311. loc = strstr(payload, "messageId");
  4312. while (loc[strlen("messageId")+3+c] != '\"')
  4313. {
  4314. sstr[c] = loc[strlen("messageId")+3+c];
  4315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(tempmessageId,sstr);
  4320. //===============================
  4321. // data
  4322. //===============================
  4323. memset(sstr ,0, sizeof(sstr) );
  4324. c = 0;
  4325. loc = strstr(payload, "data");
  4326. printf("loc=%s\n",loc);
  4327. while (loc[strlen("data")+3+c] != '\"')
  4328. {
  4329. sstr[c] = loc[strlen("data")+3+c];
  4330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4331. c++;
  4332. }
  4333. sstr[c] = '\0';
  4334. strcpy(tempdata,sstr);
  4335. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4336. }
  4337. else
  4338. {
  4339. char guid[37]={0};
  4340. random_uuid(guid);
  4341. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4342. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4343. }
  4344. LWS_Send(message);
  4345. return result;
  4346. }
  4347. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4348. {
  4349. mtrace();
  4350. int result = FAIL;
  4351. int connectorIdInt, durationInt;
  4352. char chargingRateUnitStr[4]={0};
  4353. //int tempconnectorIdInt,
  4354. int tempdurationInt;
  4355. float tempminChargingRateFloat = 0.0;
  4356. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4357. int tempStartPeriodInt=0;
  4358. float tempLimitInt=0.0;//0.1;
  4359. int tempNumberPhasesInt=0;
  4360. char fname[200];
  4361. char comfirmstr[20];
  4362. //float totallimit =0.0;
  4363. float MinChargingRate =0.0;
  4364. //double diff_t;
  4365. //struct tm tp;
  4366. FILE *fptr1;
  4367. int c = 0;
  4368. //int i = 0;
  4369. char * pch;
  4370. char *loc;
  4371. char sstr[200]={ 0 };
  4372. int n_chargingProfile = 0;
  4373. int n_SchedulePeriods = 0;
  4374. char SchedulePeriodList[10][200]={0};
  4375. char sLineWord[1600]={0};
  4376. //int n_periods = 0;
  4377. char word[1000]={0};
  4378. int confirmPeriods = 0;
  4379. struct StructProfile ChargePointMaxProfile;
  4380. struct StructProfile TxDefaultProfile;
  4381. struct StructProfile TxProfile;
  4382. struct StructProfile TxDefaultProfiletemp[2]={0};
  4383. int TxDefaultProfileFileIsNull=FALSE;
  4384. int ChargePointMaxProfileIsNull=FALSE;
  4385. int TxProfileIsNull=FALSE;
  4386. int CompositeSceduleIndex = 0;
  4387. char ChargePointMaxProfileScheduleStr[30]={0};
  4388. char TxDefaultProfileScheduleStr[30]={0};
  4389. char TxProfileScheduleStr[30]={0};
  4390. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4391. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4392. memset(&TxProfile,0,sizeof(struct StructProfile));
  4393. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4394. c=0;
  4395. loc = strstr(payload, "connectorId");
  4396. memset(sstr ,0, sizeof(sstr) );
  4397. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4398. {
  4399. sstr[c] = loc[strlen("connectorId")+2+c];
  4400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4401. c++;
  4402. }
  4403. sstr[c] = '\0';
  4404. connectorIdInt = atoi(sstr);
  4405. c=0;
  4406. loc = strstr(payload, "duration");
  4407. memset(sstr ,0, sizeof(sstr) );
  4408. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4409. {
  4410. sstr[c] = loc[strlen("duration")+2+c];
  4411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. durationInt = atoi(sstr);
  4416. c = 0;
  4417. loc = strstr(payload, "chargingRateUnit");
  4418. memset(sstr ,0, sizeof(sstr) );
  4419. if(loc == NULL)
  4420. {
  4421. }
  4422. else
  4423. {
  4424. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4425. {
  4426. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4427. c++;
  4428. }
  4429. sstr[c] = '\0';
  4430. strcpy(chargingRateUnitStr, sstr);
  4431. }
  4432. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4433. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4434. if(connectorIdInt==0) // connectorId is 0
  4435. {
  4436. //******************************ChargePointMaxProfile*****************************************************/
  4437. strcpy(fname, ChargePointMaxProfile_JSON );
  4438. char word[30]={0};
  4439. char sLineWord[1060]={0};
  4440. int n_chargingProfile=0;
  4441. ChargePointMaxProfileIsNull=TRUE;
  4442. if((access(fname,F_OK))!=-1)
  4443. {
  4444. fptr1 = fopen(fname, "r");
  4445. int c;
  4446. c = fgetc(fptr1);
  4447. //DEBUG_INFO("c:%d\n",c);
  4448. rewind(fptr1);
  4449. if(c == EOF)
  4450. {
  4451. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4452. ChargePointMaxProfileIsNull=TRUE;
  4453. fclose(fptr1);
  4454. }
  4455. else
  4456. {
  4457. ChargePointMaxProfileIsNull=FALSE;
  4458. while(fscanf(fptr1, "%s", word) != EOF)
  4459. {
  4460. if(strcmp(word, "chargingProfileId") == 0)
  4461. {
  4462. n_chargingProfile = n_chargingProfile + 1;
  4463. printf("Found\n");
  4464. }
  4465. }
  4466. rewind(fptr1);
  4467. //search Charging Profile Element
  4468. int i= 0;
  4469. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4470. #if 0
  4471. /***********connectorId****************/
  4472. c = 0;
  4473. loc = strstr(sLineWord, "connectorId");
  4474. // printf("loc=%s\n",loc);
  4475. memset(sstr ,0, sizeof(sstr) );
  4476. while (loc[strlen("connectorId")+2+c] != ',')
  4477. {
  4478. sstr[c] = loc[strlen("connectorId")+2+c];
  4479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4480. c++;
  4481. }
  4482. sstr[c] = '\0';
  4483. tempconnectorIdInt = atoi(sstr);
  4484. #endif
  4485. //***********validFrom**************/
  4486. c = 0;
  4487. loc = strstr(sLineWord, "validFrom");
  4488. //DEBUG_INFO("loc=%s\n",loc);
  4489. memset(sstr ,0, sizeof(sstr) );
  4490. if(loc != NULL)
  4491. {
  4492. while (loc[3+strlen("validFrom")+c] != '\"')
  4493. {
  4494. sstr[c] = loc[3+strlen("validFrom")+c];
  4495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4496. c++;
  4497. }
  4498. sstr[c] = '\0';
  4499. DEBUG_INFO("validFrom=%s\n",sstr);
  4500. strcpy(tempvalidFromStr,sstr);
  4501. }
  4502. else
  4503. {
  4504. strcpy(tempvalidFromStr,"");
  4505. }
  4506. //**********startSchedule**********/
  4507. c = 0;
  4508. loc = strstr(sLineWord, "startSchedule");
  4509. //DEBUG_INFO("loc=%s\n",loc);
  4510. memset(sstr ,0, sizeof(sstr) );
  4511. while (loc[3+strlen("startSchedule")+c] != '\"')
  4512. {
  4513. sstr[c] = loc[3+strlen("startSchedule")+c];
  4514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4515. c++;
  4516. }
  4517. sstr[c] = '\0';
  4518. strcpy(tempstartScheduleStr, sstr);
  4519. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4520. //**********chargingRateUnit**********/
  4521. c = 0;
  4522. loc = strstr(sLineWord, "chargingRateUnit");
  4523. memset(sstr ,0, sizeof(sstr) );
  4524. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4525. {
  4526. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4527. c++;
  4528. }
  4529. sstr[c] = '\0';
  4530. strcpy(tempchargingRateUnitStr, sstr);
  4531. //**********minChargingRate*******/
  4532. c = 0;
  4533. loc = strstr(sLineWord, "minChargingRate");
  4534. //printf("loc=%s\n",loc);
  4535. if(loc != NULL)
  4536. {
  4537. memset(sstr ,0, sizeof(sstr) );
  4538. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4539. {
  4540. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4541. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4542. c++;
  4543. }
  4544. sstr[c] = '\0';
  4545. tempminChargingRateFloat = atof(sstr);
  4546. }
  4547. else
  4548. {
  4549. tempminChargingRateFloat = 0.0;
  4550. }
  4551. //
  4552. #if 0
  4553. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4554. tp.tm_isdst = -1;
  4555. time_t utc = mktime(&tp);
  4556. // current time
  4557. time_t t = time(NULL);
  4558. #endif
  4559. //diff_t = difftime(t, utc);
  4560. //parsing strings to words
  4561. i = 0;
  4562. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4563. loc = loc+3+strlen("chargingSchedulePeriod");
  4564. pch = strtok(loc ,"{");
  4565. while (pch != NULL)
  4566. {
  4567. strcpy(SchedulePeriodList[i], pch);
  4568. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4569. //printf ("%s\n",pch);
  4570. pch = strtok (NULL, "{");
  4571. i = i + 1;
  4572. }
  4573. n_SchedulePeriods = i;
  4574. for(int i=0;i<n_SchedulePeriods;i++)
  4575. {
  4576. //*************startPeriod****************/
  4577. c = 0;
  4578. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4579. memset(sstr ,0, sizeof(sstr) );
  4580. while (loc[strlen("startPeriod")+2+c] != ',')
  4581. {
  4582. sstr[c] = loc[strlen("startPeriod")+2+c];
  4583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4584. c++;
  4585. }
  4586. sstr[c] = '\0';
  4587. tempStartPeriodInt = atoi(sstr);
  4588. //*************limit****************/
  4589. c = 0;
  4590. loc = strstr(SchedulePeriodList[i], "limit");
  4591. memset(sstr ,0, sizeof(sstr) );
  4592. while (loc[strlen("limit")+2+c] != ',')
  4593. {
  4594. sstr[c] = loc[strlen("limit")+2+c];
  4595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4596. c++;
  4597. }
  4598. sstr[c] = '\0';
  4599. tempLimitInt = atof(sstr);
  4600. //*************numberPhases****************/
  4601. c = 0;
  4602. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4603. memset(sstr ,0, sizeof(sstr) );
  4604. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4605. {
  4606. sstr[c] = loc[strlen("numberPhases")+2+c];
  4607. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. tempNumberPhasesInt = atoi(sstr);
  4612. ChargePointMaxProfile.Duration = durationInt;
  4613. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4614. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4615. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4616. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4617. }
  4618. if(MinChargingRate < tempminChargingRateFloat)
  4619. MinChargingRate = tempminChargingRateFloat;
  4620. }
  4621. }// End of file ChargingProfile
  4622. } //THE END OF ACCESS ChargePointMaxProfile
  4623. //******************************TxDefaultProfile***********************************************/
  4624. strcpy(fname, TxDefaultProfile_0_JSON);
  4625. memset(word, 0, 30);
  4626. memset(sLineWord, 0, 1060);
  4627. //char word[30]={0};
  4628. //char sLineWord[1060]={0};
  4629. n_chargingProfile=0;
  4630. TxDefaultProfileFileIsNull=TRUE;
  4631. if((access(fname,F_OK))!=-1)
  4632. {
  4633. fptr1 = fopen(fname, "r");
  4634. c = 0;
  4635. c = fgetc(fptr1);
  4636. //DEBUG_INFO("c:%d\n",c);
  4637. rewind(fptr1);
  4638. if(c == EOF)
  4639. {
  4640. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4641. TxDefaultProfileFileIsNull=TRUE;
  4642. fclose(fptr1);
  4643. }
  4644. else
  4645. {
  4646. TxDefaultProfileFileIsNull=FALSE;
  4647. while(fscanf(fptr1, "%s", word) != EOF)
  4648. {
  4649. if(strcmp(word, "chargingProfileId") == 0)
  4650. {
  4651. n_chargingProfile = n_chargingProfile + 1;
  4652. printf("Found\n");
  4653. }
  4654. }
  4655. rewind(fptr1);
  4656. //search Charging Profile Element
  4657. int i= 0;
  4658. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4659. #if 0
  4660. /***********connectorId****************/
  4661. c = 0;
  4662. loc = strstr(sLineWord, "connectorId");
  4663. // printf("loc=%s\n",loc);
  4664. memset(sstr ,0, sizeof(sstr) );
  4665. while (loc[strlen("connectorId")+2+c] != ',')
  4666. {
  4667. sstr[c] = loc[strlen("connectorId")+2+c];
  4668. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4669. c++;
  4670. }
  4671. sstr[c] = '\0';
  4672. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4673. tempconnectorIdInt = atoi(sstr);
  4674. #endif
  4675. //***********validFrom**************/
  4676. c = 0;
  4677. loc = strstr(sLineWord, "validFrom");
  4678. //DEBUG_INFO("loc=%s\n",loc);
  4679. memset(sstr ,0, sizeof(sstr) );
  4680. if(loc != NULL)
  4681. {
  4682. while (loc[3+strlen("validFrom")+c] != '\"')
  4683. {
  4684. sstr[c] = loc[3+strlen("validFrom")+c];
  4685. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4686. c++;
  4687. }
  4688. sstr[c] = '\0';
  4689. DEBUG_INFO("validFrom=%s\n",sstr);
  4690. strcpy(tempvalidFromStr,sstr);
  4691. }
  4692. else
  4693. {
  4694. strcpy(tempvalidFromStr,"");
  4695. }
  4696. //**********startSchedule**********/
  4697. c = 0;
  4698. loc = strstr(sLineWord, "startSchedule");
  4699. //DEBUG_INFO("loc=%s\n",loc);
  4700. memset(sstr ,0, sizeof(sstr) );
  4701. while (loc[3+strlen("startSchedule")+c] != '\"')
  4702. {
  4703. sstr[c] = loc[3+strlen("startSchedule")+c];
  4704. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4705. c++;
  4706. }
  4707. sstr[c] = '\0';
  4708. strcpy(tempstartScheduleStr, sstr);
  4709. strcpy(TxDefaultProfileScheduleStr, sstr);
  4710. //**********chargingRateUnit**********/
  4711. c = 0;
  4712. loc = strstr(sLineWord, "chargingRateUnit");
  4713. memset(sstr ,0, sizeof(sstr) );
  4714. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4715. {
  4716. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4717. c++;
  4718. }
  4719. sstr[c] = '\0';
  4720. strcpy(tempchargingRateUnitStr, sstr);
  4721. //**********minChargingRate*******/
  4722. c = 0;
  4723. loc = strstr(sLineWord, "minChargingRate");
  4724. //printf("loc=%s\n",loc);
  4725. if(loc != NULL)
  4726. {
  4727. memset(sstr ,0, sizeof(sstr) );
  4728. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4729. {
  4730. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4732. c++;
  4733. }
  4734. sstr[c] = '\0';
  4735. tempminChargingRateFloat = atof(sstr);
  4736. }
  4737. else
  4738. {
  4739. tempminChargingRateFloat = 0.0;
  4740. }
  4741. #if 0
  4742. //
  4743. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4744. tp.tm_isdst = -1;
  4745. time_t utc = mktime(&tp);
  4746. // current time
  4747. time_t t = time(NULL);
  4748. //diff_t = difftime(t, utc);
  4749. #endif
  4750. //parsing strings to words
  4751. i = 0;
  4752. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4753. loc = loc+3+strlen("chargingSchedulePeriod");
  4754. pch = strtok(loc ,"{");
  4755. while (pch != NULL)
  4756. {
  4757. strcpy(SchedulePeriodList[i], pch);
  4758. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4759. //printf ("%s\n",pch);
  4760. pch = strtok (NULL, "{");
  4761. i = i + 1;
  4762. }
  4763. n_SchedulePeriods = i;
  4764. for(int i=0;i<n_SchedulePeriods;i++)
  4765. {
  4766. //*************startPeriod****************/
  4767. c = 0;
  4768. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4769. memset(sstr ,0, sizeof(sstr) );
  4770. while (loc[strlen("startPeriod")+2+c] != ',')
  4771. {
  4772. sstr[c] = loc[strlen("startPeriod")+2+c];
  4773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4774. c++;
  4775. }
  4776. sstr[c] = '\0';
  4777. tempStartPeriodInt = atoi(sstr);
  4778. //*************limit****************/
  4779. c = 0;
  4780. loc = strstr(SchedulePeriodList[i], "limit");
  4781. memset(sstr ,0, sizeof(sstr) );
  4782. while (loc[strlen("limit")+2+c] != ',')
  4783. {
  4784. sstr[c] = loc[strlen("limit")+2+c];
  4785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4786. c++;
  4787. }
  4788. sstr[c] = '\0';
  4789. tempLimitInt = atof(sstr);
  4790. //*************numberPhases****************/
  4791. c = 0;
  4792. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4793. memset(sstr ,0, sizeof(sstr) );
  4794. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4795. {
  4796. sstr[c] = loc[strlen("numberPhases")+2+c];
  4797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4798. c++;
  4799. }
  4800. sstr[c] = '\0';
  4801. tempNumberPhasesInt = atoi(sstr);
  4802. TxDefaultProfile.Duration = durationInt;
  4803. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4804. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4805. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4806. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4807. }
  4808. if(MinChargingRate < tempminChargingRateFloat)
  4809. MinChargingRate = tempminChargingRateFloat;
  4810. }
  4811. }
  4812. }// the end of ACCESS TxDefaultProfile
  4813. //--------------------- Composite Schedule-----------------------------//
  4814. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4815. {
  4816. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4817. struct tm tp;
  4818. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4819. tp.tm_isdst = -1;
  4820. time_t utc = mktime(&tp);
  4821. time_t t = time(NULL);
  4822. double diff_f = difftime(t, utc);
  4823. int diff_i; //= (int)diff_f;
  4824. int quotient; //= diff_i / 86400;//86400 seconds/day
  4825. int period = 0;
  4826. if(diff_f >= 0)
  4827. {
  4828. diff_i = (int)diff_f;
  4829. quotient = diff_i / 86400;
  4830. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4831. {
  4832. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4833. {
  4834. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4835. {
  4836. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4837. }
  4838. else
  4839. {
  4840. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4841. }
  4842. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4843. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4844. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4845. period = period + 1;
  4846. }
  4847. }
  4848. }
  4849. confirmPeriods = period;
  4850. }
  4851. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4852. {
  4853. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4854. struct tm tp;
  4855. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4856. tp.tm_isdst = -1;
  4857. time_t utc = mktime(&tp);
  4858. time_t t = time(NULL);
  4859. double diff_f = difftime(t, utc);
  4860. int diff_i; // = (int)diff_f;
  4861. int quotient; // = diff_i / 86400;//86400 seconds/day
  4862. int period = 0;
  4863. if(diff_f >= 0)
  4864. {
  4865. diff_i = (int)diff_f;
  4866. quotient = diff_i / 86400;//86400 seconds/day
  4867. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4868. {
  4869. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4870. {
  4871. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4872. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4873. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4874. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4875. period = period + 1;
  4876. }
  4877. }
  4878. }
  4879. confirmPeriods = period;
  4880. }
  4881. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4882. {
  4883. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4884. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4885. {
  4886. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4887. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4888. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4889. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4890. }
  4891. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4892. }
  4893. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4894. {
  4895. confirmPeriods = 0;
  4896. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4897. goto end;
  4898. }
  4899. //* Define temporary variables */
  4900. struct tm *gtime;
  4901. time_t now;
  4902. char buf[28];
  4903. /* Read the current system time */
  4904. time(&now);
  4905. /* Convert the system time to GMT (now UTC) */
  4906. gtime = gmtime(&now);
  4907. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4908. // make .conf
  4909. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4910. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4911. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4912. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4913. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4914. }
  4915. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4916. {
  4917. //*****************************ChargePointMaxProfile******************************************/
  4918. strcpy(fname, ChargePointMaxProfile_JSON);
  4919. ChargePointMaxProfileIsNull=TRUE;
  4920. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4921. {
  4922. fptr1 = fopen(fname, "r");
  4923. int c;
  4924. c = fgetc(fptr1);
  4925. //DEBUG_INFO("c:%d\n",c);
  4926. rewind(fptr1);
  4927. if(c == EOF)
  4928. {
  4929. DEBUG_INFO("\n End of file reached.");
  4930. ChargePointMaxProfileIsNull=TRUE;
  4931. fclose(fptr1);
  4932. }
  4933. else
  4934. {
  4935. ChargePointMaxProfileIsNull=FALSE;
  4936. while(fscanf(fptr1, "%s", word) != EOF)
  4937. {
  4938. if(strcmp(word, "chargingProfileId") == 0)
  4939. {
  4940. n_chargingProfile = n_chargingProfile + 1;
  4941. }
  4942. }
  4943. rewind(fptr1);
  4944. //search Charging Profile Element
  4945. int i = 0;
  4946. int j = 0;
  4947. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4948. #if 0
  4949. /***********connectorId****************/
  4950. c = 0;
  4951. loc = strstr(sLineWord, "connectorId");
  4952. memset(sstr ,0, sizeof(sstr) );
  4953. while (loc[strlen("connectorId")+2+c] != ',')
  4954. {
  4955. sstr[c] = loc[strlen("connectorId")+2+c];
  4956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4957. c++;
  4958. }
  4959. sstr[c] = '\0';
  4960. tempconnectorIdInt = atoi(sstr);
  4961. #endif
  4962. //***********validFrom**************/
  4963. c = 0;
  4964. loc = strstr(sLineWord, "validFrom");
  4965. if(loc != NULL)
  4966. {
  4967. memset(sstr ,0, sizeof(sstr) );
  4968. while (loc[3+strlen("validFrom")+c] != '\"')
  4969. {
  4970. sstr[c] = loc[3+strlen("validFrom")+c];
  4971. c++;
  4972. }
  4973. sstr[c] = '\0';
  4974. strcpy(tempvalidFromStr,sstr);
  4975. }
  4976. else
  4977. {
  4978. strcpy(tempvalidFromStr,"");
  4979. }
  4980. //***********validFrom**************/
  4981. c = 0;
  4982. loc = strstr(sLineWord, "duration");
  4983. if(loc != NULL)
  4984. {
  4985. memset(sstr ,0, sizeof(sstr) );
  4986. while (loc[2+strlen("duration")+c] != ',')
  4987. {
  4988. sstr[c] = loc[2+strlen("duration")+c];
  4989. c++;
  4990. }
  4991. sstr[c] = '\0';
  4992. tempdurationInt = atoi(sstr);
  4993. }
  4994. else
  4995. {
  4996. tempdurationInt = 0;
  4997. }
  4998. //**********startSchedule**********/
  4999. c = 0;
  5000. loc = strstr(sLineWord, "startSchedule");
  5001. memset(sstr ,0, sizeof(sstr) );
  5002. while (loc[3+strlen("startSchedule")+c] != '\"')
  5003. {
  5004. sstr[c] = loc[3+strlen("startSchedule")+c];
  5005. c++;
  5006. }
  5007. sstr[c] = '\0';
  5008. strcpy(tempstartScheduleStr, sstr);
  5009. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5010. //**********chargingRateUnit**********/
  5011. c = 0;
  5012. loc = strstr(sLineWord, "chargingRateUnit");
  5013. memset(sstr ,0, sizeof(sstr) );
  5014. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5015. {
  5016. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5017. c++;
  5018. }
  5019. sstr[c] = '\0';
  5020. strcpy(tempchargingRateUnitStr, sstr);
  5021. //**********minChargingRate*******/
  5022. c = 0;
  5023. loc = strstr(sLineWord, "minChargingRate");
  5024. if(loc != NULL)
  5025. {
  5026. memset(sstr ,0, sizeof(sstr) );
  5027. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5028. {
  5029. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5030. c++;
  5031. }
  5032. sstr[c] = '\0';
  5033. tempminChargingRateFloat = atof(sstr);
  5034. }
  5035. else
  5036. {
  5037. tempminChargingRateFloat = 0.0;
  5038. }
  5039. #if 0
  5040. //
  5041. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5042. tp.tm_isdst = -1;
  5043. time_t utc = mktime(&tp);
  5044. time_t t = time(NULL);
  5045. //diff_t = difftime(t, utc);
  5046. #endif
  5047. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5048. //DEBUG_INFO(" debug 5 -1\n");
  5049. //parsing strings to words
  5050. i = 0;
  5051. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5052. loc = loc+3+strlen("chargingSchedulePeriod");
  5053. pch = strtok(loc ,"{");
  5054. while (pch != NULL)
  5055. {
  5056. strcpy(SchedulePeriodList[i], pch);
  5057. pch = strtok (NULL, "{");
  5058. i = i + 1;
  5059. }
  5060. n_SchedulePeriods = i;
  5061. for(int i=0;i<n_SchedulePeriods;i++)
  5062. {
  5063. //*************startPeriod****************/
  5064. c = 0;
  5065. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5066. memset(sstr ,0, sizeof(sstr) );
  5067. while (loc[strlen("startPeriod")+2+c] != ',')
  5068. {
  5069. sstr[c] = loc[strlen("startPeriod")+2+c];
  5070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5071. c++;
  5072. }
  5073. sstr[c] = '\0';
  5074. tempStartPeriodInt = atoi(sstr);
  5075. //*************limit****************/
  5076. c = 0;
  5077. loc = strstr(SchedulePeriodList[i], "limit");
  5078. memset(sstr ,0, sizeof(sstr) );
  5079. while (loc[strlen("limit")+2+c] != ',')
  5080. {
  5081. sstr[c] = loc[strlen("limit")+2+c];
  5082. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5083. c++;
  5084. }
  5085. sstr[c] = '\0';
  5086. tempLimitInt = atof(sstr);
  5087. //*************numberPhases****************/
  5088. c = 0;
  5089. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5090. memset(sstr ,0, sizeof(sstr) );
  5091. while (loc[strlen("numberPhases")+2+c] != '}')
  5092. {
  5093. sstr[c] = loc[strlen("numberPhases")+2+c];
  5094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5095. c++;
  5096. }
  5097. sstr[c] = '\0';
  5098. tempNumberPhasesInt = atoi(sstr);
  5099. if(j == 0)
  5100. {
  5101. ChargePointMaxProfile.Duration = tempdurationInt;
  5102. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5103. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5104. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5105. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5106. }
  5107. }
  5108. if(MinChargingRate < tempminChargingRateFloat)
  5109. {
  5110. MinChargingRate = tempminChargingRateFloat;
  5111. }
  5112. if(confirmPeriods < n_SchedulePeriods)
  5113. {
  5114. confirmPeriods = n_SchedulePeriods;
  5115. }
  5116. j = j + 1;
  5117. }
  5118. fclose(fptr1);
  5119. }
  5120. }// the end of access file ChargePointMaxProfile
  5121. //****************************TxDefaultProfile************************************************/
  5122. #if 0
  5123. switch(connectorIdInt)
  5124. {
  5125. case 0:
  5126. break;
  5127. case 1:
  5128. strcpy(fname, TxDefaultProfile_1_JSON );
  5129. break;
  5130. case 2:
  5131. strcpy(fname, TxDefaultProfile_2_JSON );
  5132. break;
  5133. default:
  5134. strcpy(fname, TxDefaultProfile_1_JSON );
  5135. break;
  5136. }
  5137. #endif
  5138. memset(fname, 0, sizeof fname);
  5139. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5140. TxDefaultProfileFileIsNull=TRUE;
  5141. if((access(fname,F_OK))!=-1)
  5142. {
  5143. fptr1 = fopen(fname, "r");
  5144. c = 0;
  5145. c = fgetc(fptr1);
  5146. //DEBUG_INFO("c:%d\n",c);
  5147. rewind(fptr1);
  5148. if(c == EOF)
  5149. {
  5150. DEBUG_INFO("\n End of file reached.");
  5151. TxDefaultProfileFileIsNull=TRUE;
  5152. fclose(fptr1);
  5153. }
  5154. else
  5155. {
  5156. TxDefaultProfileFileIsNull=FALSE;
  5157. while(fscanf(fptr1, "%s", word) != EOF)
  5158. {
  5159. if(strcmp(word, "chargingProfileId") == 0)
  5160. {
  5161. n_chargingProfile = n_chargingProfile + 1;
  5162. }
  5163. }
  5164. rewind(fptr1);
  5165. //search Charging Profile Element
  5166. int i = 0;
  5167. int j = 0;
  5168. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5169. //DEBUG_INFO(" 1-1\n");
  5170. #if 0
  5171. /***********connectorId****************/
  5172. c = 0;
  5173. loc = strstr(sLineWord, "connectorId");
  5174. memset(sstr ,0, sizeof(sstr) );
  5175. while (loc[strlen("connectorId")+2+c] != ',')
  5176. {
  5177. sstr[c] = loc[strlen("connectorId")+2+c];
  5178. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5179. c++;
  5180. }
  5181. sstr[c] = '\0';
  5182. tempconnectorIdInt = atoi(sstr);
  5183. #endif
  5184. //***********validFrom**************/
  5185. c = 0;
  5186. loc = strstr(sLineWord, "validFrom");
  5187. if(loc != NULL)
  5188. {
  5189. memset(sstr ,0, sizeof(sstr) );
  5190. while (loc[3+strlen("validFrom")+c] != '\"')
  5191. {
  5192. sstr[c] = loc[3+strlen("validFrom")+c];
  5193. c++;
  5194. }
  5195. sstr[c] = '\0';
  5196. strcpy(tempvalidFromStr,sstr);
  5197. }
  5198. else
  5199. {
  5200. strcpy(tempvalidFromStr,"");
  5201. }
  5202. //***********validFrom**************/
  5203. c = 0;
  5204. loc = strstr(sLineWord, "duration");
  5205. if(loc != NULL)
  5206. {
  5207. memset(sstr ,0, sizeof(sstr) );
  5208. while (loc[2+strlen("duration")+c] != ',')
  5209. {
  5210. sstr[c] = loc[2+strlen("duration")+c];
  5211. c++;
  5212. }
  5213. sstr[c] = '\0';
  5214. tempdurationInt = atoi(sstr);
  5215. }
  5216. else
  5217. {
  5218. tempdurationInt = 0;
  5219. }
  5220. //**********startSchedule**********/
  5221. c = 0;
  5222. loc = strstr(sLineWord, "startSchedule");
  5223. memset(sstr ,0, sizeof(sstr) );
  5224. while (loc[3+strlen("startSchedule")+c] != '\"')
  5225. {
  5226. sstr[c] = loc[3+strlen("startSchedule")+c];
  5227. c++;
  5228. }
  5229. sstr[c] = '\0';
  5230. strcpy(tempstartScheduleStr, sstr);
  5231. strcpy(TxDefaultProfileScheduleStr, sstr);
  5232. //**********chargingRateUnit**********/
  5233. c = 0;
  5234. loc = strstr(sLineWord, "chargingRateUnit");
  5235. memset(sstr ,0, sizeof(sstr) );
  5236. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5237. {
  5238. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5239. c++;
  5240. }
  5241. sstr[c] = '\0';
  5242. strcpy(tempchargingRateUnitStr, sstr);
  5243. //**********minChargingRate*******/
  5244. c = 0;
  5245. loc = strstr(sLineWord, "minChargingRate");
  5246. if(loc != NULL)
  5247. {
  5248. memset(sstr ,0, sizeof(sstr) );
  5249. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5250. {
  5251. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5252. c++;
  5253. }
  5254. sstr[c] = '\0';
  5255. tempminChargingRateFloat = atof(sstr);
  5256. }
  5257. else
  5258. {
  5259. tempminChargingRateFloat = 0.0;
  5260. }
  5261. #if 0
  5262. //
  5263. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5264. tp.tm_isdst = -1;
  5265. time_t utc = mktime(&tp);
  5266. time_t t = time(NULL);
  5267. //diff_t = difftime(t, utc);
  5268. #endif
  5269. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5270. //parsing strings to words
  5271. i = 0;
  5272. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5273. loc = loc+3+strlen("chargingSchedulePeriod");
  5274. pch = strtok(loc ,"{");
  5275. while (pch != NULL)
  5276. {
  5277. strcpy(SchedulePeriodList[i], pch);
  5278. pch = strtok (NULL, "{");
  5279. i = i + 1;
  5280. }
  5281. n_SchedulePeriods = i;
  5282. for(int i=0;i<n_SchedulePeriods;i++)
  5283. {
  5284. //*************startPeriod****************/
  5285. c = 0;
  5286. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5287. memset(sstr ,0, sizeof(sstr) );
  5288. while (loc[strlen("startPeriod")+2+c] != ',')
  5289. {
  5290. sstr[c] = loc[strlen("startPeriod")+2+c];
  5291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5292. c++;
  5293. }
  5294. sstr[c] = '\0';
  5295. tempStartPeriodInt = atoi(sstr);
  5296. //*************limit****************/
  5297. c = 0;
  5298. loc = strstr(SchedulePeriodList[i], "limit");
  5299. memset(sstr ,0, sizeof(sstr) );
  5300. while (loc[strlen("limit")+2+c] != ',')
  5301. {
  5302. sstr[c] = loc[strlen("limit")+2+c];
  5303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5304. c++;
  5305. }
  5306. sstr[c] = '\0';
  5307. tempLimitInt = atof(sstr);
  5308. //*************numberPhases****************/
  5309. c = 0;
  5310. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5311. memset(sstr ,0, sizeof(sstr) );
  5312. while (loc[strlen("numberPhases")+2+c] != '}')
  5313. {
  5314. sstr[c] = loc[strlen("numberPhases")+2+c];
  5315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5316. c++;
  5317. }
  5318. sstr[c] = '\0';
  5319. tempNumberPhasesInt = atoi(sstr);
  5320. if(j == 0)
  5321. {
  5322. TxDefaultProfile.Duration = tempdurationInt;
  5323. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5324. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5325. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5326. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5327. }
  5328. else
  5329. {
  5330. //other stack level charging Profile
  5331. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5332. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5333. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5334. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5335. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5336. }
  5337. }
  5338. if(MinChargingRate < tempminChargingRateFloat)
  5339. MinChargingRate = tempminChargingRateFloat;
  5340. if(confirmPeriods < n_SchedulePeriods)
  5341. confirmPeriods = n_SchedulePeriods;
  5342. j = j + 1;
  5343. //DEBUG_INFO(" 1-2\n");
  5344. }
  5345. fclose(fptr1);
  5346. //Stacking Charging Profiles
  5347. for(int l=0; l <(j-1) ;l++)
  5348. {
  5349. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5350. {
  5351. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5352. {
  5353. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5354. {
  5355. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5356. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5357. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5358. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5359. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5360. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5361. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5362. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5363. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5364. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5365. }
  5366. else
  5367. {
  5368. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5369. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5370. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5371. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5372. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5373. }
  5374. }
  5375. }
  5376. }
  5377. //end of Stacking Charging Profiles
  5378. }
  5379. }// the end of ACCESS TxDefaultProfile
  5380. //****************************TxProfile************************************************/
  5381. #if 0
  5382. switch(connectorIdInt)
  5383. {
  5384. case 0:
  5385. break;
  5386. case 1:
  5387. strcpy(fname, TxProfile_1_JSON );
  5388. break;
  5389. case 2:
  5390. strcpy(fname, TxProfile_2_JSON );
  5391. break;
  5392. default:
  5393. strcpy(fname, TxProfile_1_JSON );
  5394. break;
  5395. }
  5396. #endif
  5397. memset(fname, 0, sizeof fname);
  5398. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5399. TxProfileIsNull=TRUE;
  5400. if((access(fname,F_OK))!=-1)
  5401. {
  5402. fptr1 = fopen(fname, "r");
  5403. c = 0;
  5404. c = fgetc(fptr1);
  5405. //DEBUG_INFO("c:%d\n",c);
  5406. rewind(fptr1);
  5407. if(c == EOF)
  5408. {
  5409. DEBUG_INFO("\n End of file reached.");
  5410. TxProfileIsNull=TRUE;
  5411. fclose(fptr1);
  5412. }
  5413. else
  5414. {
  5415. TxProfileIsNull=FALSE;
  5416. while(fscanf(fptr1, "%s", word) != EOF)
  5417. {
  5418. if(strcmp(word, "chargingProfileId") == 0)
  5419. {
  5420. n_chargingProfile = n_chargingProfile + 1;
  5421. }
  5422. }
  5423. rewind(fptr1);
  5424. //search Charging Profile Element
  5425. int i= 0;
  5426. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5427. #if 0
  5428. /***********connectorId****************/
  5429. c = 0;
  5430. loc = strstr(sLineWord, "connectorId");
  5431. memset(sstr ,0, sizeof(sstr) );
  5432. while (loc[strlen("connectorId")+2+c] != ',')
  5433. {
  5434. sstr[c] = loc[strlen("connectorId")+2+c];
  5435. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5436. c++;
  5437. }
  5438. sstr[c] = '\0';
  5439. tempconnectorIdInt = atoi(sstr);
  5440. #endif
  5441. //***********validFrom**************/
  5442. c = 0;
  5443. loc = strstr(sLineWord, "validFrom");
  5444. if(loc != NULL)
  5445. {
  5446. memset(sstr ,0, sizeof(sstr) );
  5447. while (loc[3+strlen("validFrom")+c] != '\"')
  5448. {
  5449. sstr[c] = loc[3+strlen("validFrom")+c];
  5450. c++;
  5451. }
  5452. sstr[c] = '\0';
  5453. strcpy(tempvalidFromStr,sstr);
  5454. }
  5455. else
  5456. {
  5457. strcpy(tempvalidFromStr,"");
  5458. }
  5459. //**********startSchedule**********/
  5460. c = 0;
  5461. loc = strstr(sLineWord, "startSchedule");
  5462. memset(sstr ,0, sizeof(sstr) );
  5463. while (loc[3+strlen("startSchedule")+c] != '\"')
  5464. {
  5465. sstr[c] = loc[3+strlen("startSchedule")+c];
  5466. c++;
  5467. }
  5468. sstr[c] = '\0';
  5469. strcpy(tempstartScheduleStr, sstr);
  5470. strcpy(TxProfileScheduleStr, sstr);
  5471. //**********chargingRateUnit**********/
  5472. c = 0;
  5473. loc = strstr(sLineWord, "chargingRateUnit");
  5474. memset(sstr ,0, sizeof(sstr) );
  5475. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5476. {
  5477. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5478. c++;
  5479. }
  5480. sstr[c] = '\0';
  5481. strcpy(tempchargingRateUnitStr, sstr);
  5482. //**********minChargingRate*******/
  5483. c = 0;
  5484. loc = strstr(sLineWord, "minChargingRate");
  5485. if(loc != NULL)
  5486. {
  5487. memset(sstr ,0, sizeof(sstr) );
  5488. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5489. {
  5490. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5491. c++;
  5492. }
  5493. sstr[c] = '\0';
  5494. tempminChargingRateFloat = atof(sstr);
  5495. }
  5496. else
  5497. {
  5498. tempminChargingRateFloat = 0.0;
  5499. }
  5500. #if 0
  5501. //
  5502. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5503. tp.tm_isdst = -1;
  5504. time_t utc = mktime(&tp);
  5505. time_t t = time(NULL);
  5506. //diff_t = difftime(t, utc);
  5507. #endif
  5508. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5509. //parsing strings to words
  5510. i = 0;
  5511. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5512. loc = loc+3+strlen("chargingSchedulePeriod");
  5513. pch = strtok(loc ,"{");
  5514. while (pch != NULL)
  5515. {
  5516. strcpy(SchedulePeriodList[i], pch);
  5517. pch = strtok (NULL, "{");
  5518. i = i + 1;
  5519. }
  5520. n_SchedulePeriods = i;
  5521. for(int i=0;i<n_SchedulePeriods;i++)
  5522. {
  5523. //*************startPeriod****************/
  5524. c = 0;
  5525. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5526. memset(sstr ,0, sizeof(sstr) );
  5527. while (loc[strlen("startPeriod")+2+c] != ',')
  5528. {
  5529. sstr[c] = loc[strlen("startPeriod")+2+c];
  5530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5531. c++;
  5532. }
  5533. sstr[c] = '\0';
  5534. tempStartPeriodInt = atoi(sstr);
  5535. //*************limit****************/
  5536. c = 0;
  5537. loc = strstr(SchedulePeriodList[i], "limit");
  5538. memset(sstr ,0, sizeof(sstr) );
  5539. while (loc[strlen("limit")+2+c] != ',')
  5540. {
  5541. sstr[c] = loc[strlen("limit")+2+c];
  5542. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5543. c++;
  5544. }
  5545. sstr[c] = '\0';
  5546. tempLimitInt = atof(sstr);
  5547. //*************numberPhases****************/
  5548. c = 0;
  5549. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5550. memset(sstr ,0, sizeof(sstr) );
  5551. while (loc[strlen("numberPhases")+2+c] != '}')
  5552. {
  5553. sstr[c] = loc[strlen("numberPhases")+2+c];
  5554. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5555. c++;
  5556. }
  5557. sstr[c] = '\0';
  5558. tempNumberPhasesInt = atoi(sstr);
  5559. TxProfile.Duration = durationInt;
  5560. TxProfile.TotalPeriod = n_SchedulePeriods;
  5561. TxProfile.Period[i].Limit = tempLimitInt;
  5562. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5563. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5564. }
  5565. if(MinChargingRate < tempminChargingRateFloat)
  5566. MinChargingRate = tempminChargingRateFloat;
  5567. if(confirmPeriods < n_SchedulePeriods)
  5568. confirmPeriods = n_SchedulePeriods;
  5569. }
  5570. fclose(fptr1);
  5571. }
  5572. }// the end of ACCESS TxProfile
  5573. //CompositeSchedule
  5574. int period=0;
  5575. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5576. {
  5577. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5578. struct tm tp;
  5579. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5580. tp.tm_isdst = -1;
  5581. time_t utc = mktime(&tp);
  5582. time_t t = time(NULL);
  5583. double diff_f = difftime(t, utc);
  5584. int diff_i; // = (int)diff_f;
  5585. int quotient; // = diff_i / 86400;//86400 seconds/day
  5586. //int remainder = diff_i % 86400;
  5587. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5588. {
  5589. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5590. {
  5591. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5592. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5593. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5594. period = period + 1;
  5595. }
  5596. else
  5597. {
  5598. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5599. {
  5600. }
  5601. else
  5602. {
  5603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5604. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5606. period = period + 1;
  5607. }
  5608. }
  5609. }
  5610. if( diff_f >= 0)
  5611. {
  5612. diff_i = (int)diff_f;
  5613. quotient = diff_i / 86400;//86400 seconds/day
  5614. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5615. {
  5616. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5617. {
  5618. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5619. {
  5620. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5621. }
  5622. else
  5623. {
  5624. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5625. }
  5626. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5627. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5628. period = period + 1;
  5629. }
  5630. }
  5631. // Check Last Period
  5632. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5633. {
  5634. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5635. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5636. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5637. period = period + 1;
  5638. }
  5639. } // diff_f >= 0
  5640. }
  5641. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5642. {
  5643. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5644. struct tm tp;
  5645. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5646. tp.tm_isdst = -1;
  5647. time_t utc = mktime(&tp);
  5648. time_t t = time(NULL);
  5649. double diff_f = difftime(t, utc);
  5650. int diff_i;// = (int)diff_f;
  5651. int quotient; // = diff_i / 86400;//86400 seconds/day
  5652. //int remainder = diff_i % 86400;
  5653. if(diff_f >= 0)
  5654. {
  5655. diff_i = (int)diff_f;
  5656. quotient = diff_i / 86400;//86400 seconds/day
  5657. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5658. {
  5659. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5660. {
  5661. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5662. {
  5663. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5664. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5665. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5666. period = period + 1;
  5667. }
  5668. else
  5669. {
  5670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5671. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5672. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5673. period = period + 1;
  5674. }
  5675. }
  5676. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5677. {
  5678. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5679. {
  5680. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5681. {
  5682. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5683. {
  5684. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5685. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5686. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5687. period = period + 1;
  5688. }
  5689. else
  5690. {
  5691. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5692. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5693. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5694. period = period + 1;
  5695. }
  5696. }
  5697. }
  5698. }
  5699. }
  5700. } // end diff_f >= 0
  5701. }
  5702. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5703. {
  5704. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5705. struct tm tp;
  5706. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5707. tp.tm_isdst = -1;
  5708. time_t utc = mktime(&tp);
  5709. time_t t = time(NULL);
  5710. double diff_f = difftime(t, utc);
  5711. int diff_i; // = (int)diff_f;
  5712. int quotient; // = diff_i / 86400;//86400 seconds/day
  5713. //int remainder = diff_i % 86400;
  5714. if(diff_f >= 0)
  5715. {
  5716. diff_i = (int)diff_f;
  5717. quotient = diff_i / 86400;//86400 seconds/day
  5718. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5719. {
  5720. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5721. {
  5722. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5723. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5724. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5725. period = period + 1;
  5726. }
  5727. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5728. {
  5729. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5730. {
  5731. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5732. {
  5733. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5734. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5735. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5736. period = period + 1;
  5737. }
  5738. }
  5739. }
  5740. }
  5741. } // diff_f >= 0
  5742. }
  5743. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5744. {
  5745. confirmPeriods = 0;
  5746. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5747. goto end;
  5748. }
  5749. confirmPeriods = period;
  5750. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5751. //---- Define StartSchedule----/
  5752. struct tm *gtime;
  5753. time_t now;
  5754. char buf[28];
  5755. //---Read the current system time---/
  5756. time(&now);
  5757. //---Convert the system time to GMT (now UTC)---/
  5758. gtime = gmtime(&now);
  5759. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5760. // make .conf
  5761. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5762. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5763. //DEBUG_INFO(" debug 11\n");
  5764. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5765. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5766. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5767. }
  5768. else
  5769. {
  5770. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5771. }
  5772. end:
  5773. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5774. return result;
  5775. }
  5776. int handleGetConfigurationRequest(char *uuid, char *payload)
  5777. {
  5778. mtrace();
  5779. int result = FAIL;
  5780. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5781. //struct json_object *jsonitem;
  5782. int MaxKeySupported = 0;
  5783. int n_keys = 0;
  5784. char requestKey[43][50]={0};
  5785. char search[]="[";
  5786. char sstr[500]={ 0 };
  5787. //int pos;
  5788. int l, c = 0;
  5789. int i = 0;
  5790. char *delim = "\",\"";
  5791. char * pch;
  5792. char *loc = strstr(payload, search);
  5793. //********************* Parsing String ***********************************/
  5794. if(loc == NULL) {
  5795. DEBUG_INFO("no key match in Configuration \n");
  5796. }
  5797. else {
  5798. //pos = loc - payload;
  5799. l = strlen(loc)-4;
  5800. while (c < l)
  5801. {
  5802. sstr[c] = loc[c+2];
  5803. c++;
  5804. }
  5805. sstr[c] = '\0';
  5806. //parsing strings to words
  5807. pch = strtok(sstr,delim);
  5808. if(pch == NULL)
  5809. {
  5810. strcpy(requestKey[0], sstr);
  5811. }
  5812. else
  5813. {
  5814. while (pch != NULL)
  5815. {
  5816. strcpy(requestKey[i], pch);
  5817. pch = strtok (NULL, delim);
  5818. i = i + 1;
  5819. }
  5820. n_keys = i;
  5821. }
  5822. }
  5823. UnknownKeynum = 0;
  5824. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5825. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5826. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5827. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5828. if(n_keys != 0)
  5829. {
  5830. for(int i=0;i<n_keys;i++)
  5831. {
  5832. getKeyValue(requestKey[i]);
  5833. //json_object_put(jsonitem);
  5834. }
  5835. }
  5836. else
  5837. {
  5838. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5839. getKeyValue("");
  5840. }
  5841. processUnkownKey();
  5842. sendGetConfigurationConfirmation(uuid);
  5843. return result;
  5844. }
  5845. static char fnamePlusPath[100]={0};
  5846. static char fnamePWithNoPath[60]={0};
  5847. void checkUploadLog(void)
  5848. {
  5849. FILE *fp;
  5850. /* Open the command for reading. */
  5851. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5852. if (fp == NULL) {
  5853. printf("Failed to run command\n" );
  5854. exit(1);
  5855. }
  5856. int ftppathlen = 0;
  5857. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5858. int i = 0;
  5859. /* Read the output a line at a time - output it. */
  5860. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5861. if(i==0)
  5862. {
  5863. ftppathlen = strlen(fnamePlusPath);
  5864. printf("%s\n", fnamePlusPath);
  5865. fnamePlusPath[ftppathlen]='\0';
  5866. break;
  5867. }
  5868. i= i+1;
  5869. }
  5870. /* close */
  5871. pclose(fp);
  5872. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5873. {
  5874. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5875. {
  5876. fnamePlusPath[k]='\0';
  5877. }
  5878. }
  5879. i=1;
  5880. //char fname[60]={0};
  5881. while(i < ftppathlen)
  5882. {
  5883. int len=ftppathlen-i;
  5884. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5885. {
  5886. printf("compare '/' all right\n");
  5887. break;
  5888. }
  5889. i=i+1;
  5890. }
  5891. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5892. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5893. fnamePWithNoPath[i+1] = '\0';
  5894. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5895. {
  5896. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5897. {
  5898. fnamePWithNoPath[j]='\0';
  5899. }
  5900. }
  5901. FILE* fp1 = fopen(fnamePlusPath, "r");
  5902. if (fp1)
  5903. {
  5904. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5905. // file exists
  5906. fclose(fp1);
  5907. }
  5908. else
  5909. {
  5910. // file doesn't exist
  5911. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5912. }
  5913. }
  5914. static char GetDiagnosticspayloadData[300]={0};
  5915. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5916. {
  5917. mtrace();
  5918. int result = FAIL;
  5919. pthread_t t; // pthread 變數
  5920. system("exec /root/logPackTools 'log' 6");
  5921. #if 0
  5922. //char buffer [128];
  5923. time (&rawtime);
  5924. //printf("%ld\n", rawtime);
  5925. timeinfo = localtime (&rawtime);
  5926. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5927. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5928. if((access(fnamePlusPath,F_OK))!=-1)
  5929. {
  5930. DEBUG_INFO("fnamePlusPath exist.\n");
  5931. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5932. }
  5933. else
  5934. {
  5935. DEBUG_INFO("fnamePlusPath not exist!\n");
  5936. }
  5937. #endif
  5938. checkUploadLog();
  5939. memset(GetDiagnosticspayloadData, 0, 300);
  5940. strcpy(GetDiagnosticspayloadData, payload);
  5941. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5942. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5943. return result;
  5944. }
  5945. void* GetDiagnosticsProcess(void* data)
  5946. {
  5947. pthread_detach(pthread_self());
  5948. mtrace();
  5949. int retriesInt=0, retryIntervalInt=0;
  5950. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5951. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5952. 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};
  5953. int port=0;
  5954. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5955. int c = 0;
  5956. char *loc;
  5957. int isSuccess = FALSE;
  5958. char ftpbuf[200]={0};
  5959. //char temp[100]={0};
  5960. char * pch;
  5961. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5962. char str[300]={ 0 };
  5963. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5964. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5965. DEBUG_INFO("GetDiagnosticsProcess\n");
  5966. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5967. //****************location*******************/
  5968. c = 0;
  5969. memset(sstr ,0, sizeof(sstr) );
  5970. loc = strstr(str, "location");
  5971. while (loc[3+strlen("location")+c] != '\"')
  5972. {
  5973. sstr[c] = loc[3+strlen("location")+c];
  5974. c++;
  5975. }
  5976. sstr[c] = '\0';
  5977. strcpy(locationstr,sstr);
  5978. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5979. if(strcmp(locationstr,"")==0)
  5980. {
  5981. DEBUG_INFO("location is <Empty>!\n");
  5982. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5983. goto end;
  5984. }
  5985. //****************retries*******************/
  5986. c = 0;
  5987. loc = strstr(str, "retries");
  5988. if(loc == NULL)
  5989. {
  5990. retriesIsNULL = TRUE;
  5991. }
  5992. else
  5993. {
  5994. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5995. {
  5996. sstr[c] = loc[strlen("retries")+2+c];
  5997. c++;
  5998. }
  5999. sstr[c] = '\0';
  6000. retriesInt = atoi(sstr);
  6001. }
  6002. if(retriesIsNULL == TRUE)
  6003. {
  6004. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6005. }
  6006. //****************retryInterval*******************/
  6007. c = 0;
  6008. loc = strstr(str, "retryInterval");
  6009. if(loc == NULL)
  6010. {
  6011. retryIntervalIsNULL = TRUE;
  6012. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6013. }
  6014. else
  6015. {
  6016. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6017. {
  6018. sstr[c] = loc[strlen("retryInterval")+2+c];
  6019. c++;
  6020. }
  6021. sstr[c] = '\0';
  6022. retryIntervalInt = atoi(sstr);
  6023. }
  6024. //****************startTime*******************/
  6025. c = 0;
  6026. memset(sstr ,0, sizeof(sstr) );
  6027. loc = strstr(str, "startTime");
  6028. if(loc == NULL)
  6029. {
  6030. startTimeIsNULL = TRUE;
  6031. }
  6032. else
  6033. {
  6034. while (loc[3+strlen("startTime")+c] != '\"')
  6035. {
  6036. sstr[c] = loc[3+strlen("startTime")+c];
  6037. c++;
  6038. }
  6039. sstr[c] = '\0';
  6040. strcpy(startTimestr,sstr);
  6041. }
  6042. //****************stopTime*******************/
  6043. c = 0;
  6044. memset(sstr ,0, sizeof(sstr) );
  6045. loc = strstr(str, "stopTime");
  6046. if(loc == NULL)
  6047. {
  6048. stopTimeIsNULL = TRUE;
  6049. }
  6050. else
  6051. {
  6052. while (loc[3+strlen("stopTime")+c] != '\"')
  6053. {
  6054. sstr[c] = loc[3+strlen("stopTime")+c];
  6055. c++;
  6056. }
  6057. sstr[c] = '\0';
  6058. strcpy(stopTimestr,sstr);
  6059. }
  6060. memset(protocol, 0, sizeof(protocol));
  6061. memset(user, 0, sizeof(user) );
  6062. memset(password, 0, sizeof(password));
  6063. memset(host, 0, sizeof(host));
  6064. memset(path, 0, sizeof(path));
  6065. memset(ftppath, 0, sizeof(ftppath));
  6066. memset(host1, 0, sizeof(host1));
  6067. memset(path1, 0, sizeof(path1));
  6068. /*location: ftp://user:password@host:port/path*/
  6069. #if 0
  6070. time_t rawtime;
  6071. struct tm * timeinfo;
  6072. //char buffer [128];
  6073. time (&rawtime);
  6074. //printf("%ld\n", rawtime);
  6075. timeinfo = localtime (&rawtime);
  6076. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6077. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6078. #endif
  6079. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6080. if((access(fnamePlusPath,F_OK))!=-1)
  6081. {
  6082. DEBUG_INFO("fnamePlusPath exist.\n");
  6083. }
  6084. else
  6085. {
  6086. DEBUG_INFO("fnamePlusPath not exist!\n");
  6087. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6088. goto end;
  6089. }
  6090. pch=strchr(locationstr,'@');
  6091. if(pch==NULL)
  6092. {
  6093. sscanf(locationstr,
  6094. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6095. protocol, host, &port, path);
  6096. strcpy(user,"anonymous");
  6097. strcpy(password,"");
  6098. }
  6099. else
  6100. {
  6101. //DEBUG_INFO("pch=%s\n", pch);
  6102. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6103. protocol, user, password, host, &port, path);
  6104. }
  6105. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6106. {
  6107. DEBUG_INFO("protocol is not ftp/http ! \n");
  6108. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6109. goto end;
  6110. }
  6111. if(strncmp(locationstr,"http", 4) == 0)
  6112. {
  6113. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6114. sprintf(ftppath,"/%s", path);
  6115. do{
  6116. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6117. sleep(retryIntervalInt);
  6118. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6119. if(!isSuccess)
  6120. {
  6121. DEBUG_INFO("Diagnostics fail.\n");
  6122. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6123. }
  6124. else
  6125. {
  6126. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6127. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6128. }
  6129. }
  6130. else
  6131. {
  6132. sscanf(host,"%[^/]%s",host1, path1);
  6133. sprintf(ftppath,"%s", path1);
  6134. int ftppathlen=strlen(ftppath);
  6135. int i=1;
  6136. char filenametemp[50];
  6137. while(i < ftppathlen)
  6138. {
  6139. int len=ftppathlen-i;
  6140. if(ftppath[len]== 47) // '/' ascll code: 47
  6141. {
  6142. DEBUG_INFO("find '/' all right\n");
  6143. break;
  6144. }
  6145. i=i+1;
  6146. }
  6147. memset(filenametemp, 0, sizeof(filenametemp));
  6148. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6149. filenametemp[i+1] = 0;
  6150. memset(ftpbuf, 0, sizeof(ftpbuf));
  6151. if(port == 0)
  6152. port = 21;
  6153. do{
  6154. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6155. sleep(retryIntervalInt);
  6156. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6157. if(!isSuccess)
  6158. {
  6159. DEBUG_INFO("Diagnostics fail.\n");
  6160. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6161. }
  6162. else
  6163. {
  6164. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6165. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6166. }
  6167. }
  6168. end:
  6169. DiagnosticsStatusNotificationStatus = 0; //Idle
  6170. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6171. }
  6172. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6173. {
  6174. mtrace();
  6175. int result = FAIL;
  6176. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6177. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6178. {
  6179. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6180. localversion = -1;
  6181. }
  6182. else
  6183. {
  6184. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6185. OCPP_getListVerion();
  6186. }
  6187. //from db.OCPP_getListVerion
  6188. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6189. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6190. sendGetLocalListVersionConfirmation(uuid,"");
  6191. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6192. return result;
  6193. }
  6194. int handleRemoteStartRequest(char *uuid, char *payload)
  6195. {
  6196. mtrace();
  6197. int result = FAIL;
  6198. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6199. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6200. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6201. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6202. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6203. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6204. int chargingSchedulePeriodCount = 0;
  6205. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6206. int c = 0;
  6207. char *loc;
  6208. char comfirmstr[20]={0};
  6209. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6210. if(server_pending == TRUE)
  6211. {
  6212. return 0;
  6213. }
  6214. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6215. //**********connectorId****************/
  6216. c = 0;
  6217. memset(sstr ,0, sizeof(sstr) );
  6218. loc = strstr(payload, "connectorId");
  6219. if(loc == NULL)
  6220. {
  6221. connectorIdIsNULL = TRUE;
  6222. }
  6223. else
  6224. {
  6225. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6226. {
  6227. sstr[c] = loc[strlen("connectorId")+2+c];
  6228. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6229. c++;
  6230. }
  6231. sstr[c] = '\0';
  6232. connectorIdInt = atoi(sstr);
  6233. }
  6234. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6235. {
  6236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6237. goto end;
  6238. }
  6239. //****************idTag*******************/
  6240. c = 0;
  6241. memset(sstr ,0, sizeof(sstr) );
  6242. loc = strstr(payload, "idTag");
  6243. while (loc[3+strlen("idTag")+c] != '\"')
  6244. {
  6245. sstr[c] = loc[3+strlen("idTag")+c];
  6246. c++;
  6247. }
  6248. sstr[c] = '\0';
  6249. strcpy(idTagstr,sstr);
  6250. //****************chargingProfile*******************/
  6251. c = 0;
  6252. memset(sstr ,0, sizeof(sstr) );
  6253. loc = strstr(payload, "chargingProfile");
  6254. if(loc == NULL)
  6255. {
  6256. chargingProfileIsNULL = TRUE;
  6257. }
  6258. else
  6259. {
  6260. //****************chargingProfileId*******************/
  6261. c=0;
  6262. loc = strstr(payload, "chargingProfileId");
  6263. memset(sstr ,0, sizeof(sstr) );
  6264. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6265. {
  6266. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6268. c++;
  6269. }
  6270. sstr[c] = '\0';
  6271. chargingProfileIdInt = atoi(sstr);
  6272. //****************transactionId*******************/
  6273. loc = strstr(payload, "transactionId");
  6274. if(loc == NULL)
  6275. {
  6276. transactionIdIsNULL = TRUE;
  6277. }
  6278. else
  6279. {
  6280. c=0;
  6281. memset(sstr ,0, sizeof(sstr) );
  6282. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6283. {
  6284. sstr[c] = loc[strlen("transactionId")+2+c];
  6285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6286. c++;
  6287. }
  6288. sstr[c] = '\0';
  6289. transactionIdInt = atoi(sstr);
  6290. }
  6291. //****************stackLevel*******************/
  6292. c=0;
  6293. loc = strstr(payload, "stackLevel");
  6294. memset(sstr ,0, sizeof(sstr) );
  6295. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6296. {
  6297. sstr[c] = loc[strlen("stackLevel")+2+c];
  6298. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6299. c++;
  6300. }
  6301. sstr[c] = '\0';
  6302. stackLevelInt = atoi(sstr);
  6303. //****************chargingProfilePurpose*******************/
  6304. c = 0;
  6305. memset(sstr ,0, sizeof(sstr) );
  6306. loc = strstr(payload, "chargingProfilePurpose");
  6307. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6308. {
  6309. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6310. c++;
  6311. }
  6312. sstr[c] = '\0';
  6313. strcpy(chargingProfilePurposestr,sstr);
  6314. //****************chargingProfileKind*******************/
  6315. c = 0;
  6316. memset(sstr ,0, sizeof(sstr) );
  6317. loc = strstr(payload, "chargingProfileKind");
  6318. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6319. {
  6320. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6321. c++;
  6322. }
  6323. sstr[c] = '\0';
  6324. strcpy(chargingProfileKindstr,sstr);
  6325. //****************recurrencyKind*******************/
  6326. loc = strstr(payload, "recurrencyKind");
  6327. if(loc == NULL)
  6328. {
  6329. recurrencyKindIsNULL = TRUE;
  6330. }
  6331. else
  6332. {
  6333. c = 0;
  6334. memset(sstr ,0, sizeof(sstr) );
  6335. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6336. {
  6337. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6338. c++;
  6339. }
  6340. sstr[c] = '\0';
  6341. strcpy(recurrencyKindstr,sstr);
  6342. }
  6343. //****************validFrom*******************/
  6344. loc = strstr(payload, "validFrom");
  6345. if(loc == NULL)
  6346. {
  6347. validFromIsNULL = TRUE;
  6348. }
  6349. else
  6350. {
  6351. c = 0;
  6352. memset(sstr ,0, sizeof(sstr) );
  6353. while (loc[3+strlen("validFrom")+c] != '\"')
  6354. {
  6355. sstr[c] = loc[3+strlen("validFrom")+c];
  6356. c++;
  6357. }
  6358. sstr[c] = '\0';
  6359. strcpy(validFromstr,sstr);
  6360. }
  6361. //****************validTo*******************/
  6362. loc = strstr(payload, "validTo");
  6363. if(loc == NULL)
  6364. {
  6365. validToIsNULL = TRUE;
  6366. }
  6367. else
  6368. {
  6369. c = 0;
  6370. memset(sstr ,0, sizeof(sstr) );
  6371. while (loc[3+strlen("validTo")+c] != '\"')
  6372. {
  6373. sstr[c] = loc[3+strlen("validTo")+c];
  6374. c++;
  6375. }
  6376. sstr[c] = '\0';
  6377. strcpy(validTostr,sstr);
  6378. }
  6379. //****************chargingSchedule*******************/
  6380. loc = strstr(payload, "chargingSchedule");
  6381. if(loc != NULL)
  6382. {
  6383. //****************duration*******************/
  6384. loc = strstr(payload, "duration");
  6385. if(loc == NULL)
  6386. {
  6387. durationIsNULL = TRUE;
  6388. }
  6389. else
  6390. {
  6391. c=0;
  6392. memset(sstr ,0, sizeof(sstr) );
  6393. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6394. {
  6395. sstr[c] = loc[strlen("duration")+2+c];
  6396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6397. c++;
  6398. }
  6399. sstr[c] = '\0';
  6400. durationInt = atoi(sstr);
  6401. }
  6402. //****************startSchedule******************/
  6403. loc = strstr(payload, "startSchedule");
  6404. if(loc == NULL)
  6405. {
  6406. startScheduleIsNULL = TRUE;
  6407. }
  6408. else
  6409. {
  6410. c = 0;
  6411. memset(sstr ,0, sizeof(sstr) );
  6412. while (loc[3+strlen("startSchedule")+c] != '\"')
  6413. {
  6414. sstr[c] = loc[3+strlen("startSchedule")+c];
  6415. c++;
  6416. }
  6417. sstr[c] = '\0';
  6418. strcpy(startSchedulestr,sstr);
  6419. }
  6420. //****************chargingRateUnit*******************/
  6421. c = 0;
  6422. memset(sstr ,0, sizeof(sstr) );
  6423. loc = strstr(payload, "chargingRateUnit");
  6424. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6425. {
  6426. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6427. c++;
  6428. }
  6429. sstr[c] = '\0';
  6430. strcpy(chargingRateUnitstr,sstr);
  6431. //****************minChargingRate*******************/
  6432. loc = strstr(payload, "minChargingRate");
  6433. if(loc == NULL)
  6434. {
  6435. minChargingRateIsNULL = TRUE;
  6436. }
  6437. else
  6438. {
  6439. c=0;
  6440. memset(sstr ,0, sizeof(sstr) );
  6441. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6442. {
  6443. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6445. c++;
  6446. }
  6447. sstr[c] = '\0';
  6448. minChargingRateflaot = atof(sstr);
  6449. }
  6450. //****************chargingSchedulePeriod count*******************/
  6451. int what_len = strlen("startPeriod");
  6452. char *where = payload;
  6453. while ((where = strstr(where, "startPeriod"))) {
  6454. where += what_len;
  6455. chargingSchedulePeriodCount++;
  6456. }
  6457. where = payload;
  6458. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6459. {
  6460. //****************startPeriod*******************/
  6461. c=0;
  6462. loc = strstr(where, "startPeriod");
  6463. memset(sstr ,0, sizeof(sstr) );
  6464. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6465. {
  6466. sstr[c] = loc[strlen("startPeriod")+2+c];
  6467. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6468. c++;
  6469. }
  6470. sstr[c] = '\0';
  6471. startPeriodInt[periodNums] = atoi(sstr);
  6472. //****************limit*******************/
  6473. c=0;
  6474. loc = strstr(where, "limit");
  6475. memset(sstr ,0, sizeof(sstr) );
  6476. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6477. {
  6478. sstr[c] = loc[strlen("limit")+2+c];
  6479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6480. c++;
  6481. }
  6482. sstr[c] = '\0';
  6483. limitflaot[periodNums] = atof(sstr);
  6484. //****************numberPhases*******************/
  6485. loc = strstr(where, "numberPhases");
  6486. if(loc == NULL)
  6487. {
  6488. numberPhasesIsNULL = TRUE;
  6489. }
  6490. else
  6491. {
  6492. c=0;
  6493. memset(sstr ,0, sizeof(sstr) );
  6494. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6495. {
  6496. sstr[c] = loc[strlen("numberPhases")+2+c];
  6497. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6498. c++;
  6499. }
  6500. sstr[c] = '\0';
  6501. numberPhasesInt[periodNums] = atoi(sstr);
  6502. }
  6503. where = loc;
  6504. }
  6505. }
  6506. }
  6507. /*
  6508. enum _SYSTEM_STATUS
  6509. {
  6510. S_BOOTING = 0,
  6511. S_IDLE, = 1
  6512. S_AUTHORIZING, =2
  6513. S_REASSIGN_CHECK, =3
  6514. S_REASSIGN, =4
  6515. S_PRECHARGE, =5
  6516. S_PREPARING_FOR_EV, =6
  6517. S_PREPARING_FOR_EVSE, =7
  6518. S_CHARGING, =8
  6519. S_TERMINATING, =9
  6520. S_COMPLETE, =10
  6521. S_ALARM, =11
  6522. S_FAULT =12
  6523. }
  6524. */
  6525. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6526. {
  6527. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6528. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6529. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6530. //check Transaction active
  6531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6532. {
  6533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6536. {
  6537. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6538. {
  6539. //Reserved
  6540. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6541. }
  6542. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6543. {
  6544. //Reserved
  6545. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6547. goto end;
  6548. }
  6549. else
  6550. {
  6551. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6552. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6553. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6554. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6555. {
  6556. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6557. goto end;
  6558. }
  6559. }//END FOR ELSE
  6560. }
  6561. }// END FOR CHAdeMO_QUANTITY
  6562. for (int index = 0; index < CCS_QUANTITY; index++)
  6563. {
  6564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6565. {
  6566. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6567. {
  6568. //Reserved
  6569. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6570. }
  6571. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6572. {
  6573. //Reserved
  6574. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6576. goto end;
  6577. }
  6578. else
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6581. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6582. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6583. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6584. {
  6585. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6586. goto end;
  6587. }
  6588. }// END FOR ELSE
  6589. }
  6590. }// END FOR CCS_QUANTITY
  6591. for (int index = 0; index < GB_QUANTITY; index++)
  6592. {
  6593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6594. {
  6595. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6596. {
  6597. //Reserved
  6598. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6599. }
  6600. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6601. {
  6602. //Reserved
  6603. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6604. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6605. goto end;
  6606. }
  6607. else
  6608. {
  6609. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6610. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6611. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6612. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6613. {
  6614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6615. goto end;
  6616. }
  6617. }// END FOR ELSE
  6618. }
  6619. } // END FOR GB_QUANTITY
  6620. }
  6621. else
  6622. {
  6623. for (int index = 0; index < AC_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6626. {
  6627. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6628. {
  6629. //Reserved
  6630. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6631. }
  6632. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6633. {
  6634. //Reserved
  6635. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6636. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6637. goto end;
  6638. }
  6639. else
  6640. {
  6641. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6642. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6643. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6644. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6645. {
  6646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6647. goto end;
  6648. }
  6649. }//END FOR ELSE
  6650. }
  6651. }// END FOR AC_QUANTITY
  6652. }
  6653. if(chargingProfileIsNULL == FALSE)
  6654. {
  6655. //ChargingProfile
  6656. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6657. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6658. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6659. if(recurrencyKindIsNULL == FALSE) //OPTION
  6660. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6661. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6662. if(transactionIdIsNULL == FALSE) // OPTION
  6663. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6664. if(validFromIsNULL == FALSE) // OPTION
  6665. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6666. if(validToIsNULL == FALSE) //OPTION
  6667. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6668. //ChargingSchedule
  6669. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6670. if(durationIsNULL == FALSE) //OPTION
  6671. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6672. if(minChargingRateIsNULL == FALSE) //OPTION
  6673. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6674. if(startScheduleIsNULL == FALSE) //OPTION
  6675. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6676. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6677. {
  6678. //ChargingSchedulePeriod
  6679. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6680. if(numberPhasesIsNULL == FALSE)
  6681. {
  6682. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6683. }
  6684. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6685. }
  6686. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6687. {
  6688. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6690. //memset idTag
  6691. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6692. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6693. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6694. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6695. }
  6696. else
  6697. {
  6698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6699. }
  6700. }
  6701. else
  6702. {
  6703. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6705. //memset idTag
  6706. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6707. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6708. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6709. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6710. }
  6711. }
  6712. else
  6713. {
  6714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6715. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6716. }
  6717. end:
  6718. if(connectorIdIsNULL == FALSE)
  6719. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6720. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6721. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6722. //OCPP send RemoteStartConfirmation by first.
  6723. sendRemoteStartConfirmation(uuid, comfirmstr);
  6724. return result;
  6725. }
  6726. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. int match = FALSE;
  6731. int GunNO = 0;
  6732. int transactionIdInt=0;
  6733. int transactionIdIsNULL= FALSE;
  6734. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6735. int c = 0;
  6736. char *loc;
  6737. char comfirmstr[20];
  6738. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6739. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6740. if(server_pending == TRUE)
  6741. {
  6742. return 0;
  6743. }
  6744. c=0;
  6745. loc = strstr(payload, "transactionId");
  6746. if(loc == NULL)
  6747. {
  6748. transactionIdIsNULL= TRUE;
  6749. }
  6750. else
  6751. {
  6752. memset(sstr ,0, sizeof(sstr) );
  6753. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6754. {
  6755. sstr[c] = loc[strlen("transactionId")+2+c];
  6756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6757. c++;
  6758. }
  6759. sstr[c] = '\0';
  6760. transactionIdInt = atoi(sstr);
  6761. }
  6762. if(transactionIdIsNULL == FALSE)
  6763. {
  6764. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6765. {
  6766. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6767. {
  6768. //check Transaction active
  6769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6770. {
  6771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6774. {
  6775. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6776. {
  6777. match = TRUE;
  6778. GunNO = gun_index;
  6779. }
  6780. }
  6781. }// END FOR CHAdeMO_QUANTITY
  6782. for (int index = 0; index < CCS_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6785. {
  6786. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6787. {
  6788. match = TRUE;
  6789. GunNO = gun_index;
  6790. }
  6791. }
  6792. }// END FOR CCS_QUANTITY
  6793. for (int index = 0; index < GB_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6796. {
  6797. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6798. {
  6799. match = TRUE;
  6800. GunNO = gun_index;
  6801. }
  6802. }
  6803. }// END FOR GB_QUANTITY
  6804. }
  6805. else
  6806. {
  6807. for (int index = 0; index < AC_QUANTITY; index++)
  6808. {
  6809. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6810. {
  6811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6812. {
  6813. match = TRUE;
  6814. GunNO = gun_index;
  6815. }
  6816. }
  6817. }// END FOR CHAdeMO_QUANTITY
  6818. }// END FOR AC ELSE
  6819. }// CHECK IF ResponseTransactionId == transactionIdInt
  6820. }//END FOR
  6821. if( match == TRUE)
  6822. {
  6823. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6825. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6826. }
  6827. else
  6828. {
  6829. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6830. }
  6831. }
  6832. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6833. return result;
  6834. }
  6835. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6836. {
  6837. mtrace();
  6838. int result = FAIL;
  6839. int connectorIdInt=0, reservationIdInt=0;
  6840. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6841. char comfirmstr[20]={0};
  6842. char sstr[180]={ 0 };
  6843. int c = 0;
  6844. char *loc;
  6845. //char *ptr;
  6846. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6847. //***(1)connectorId ****/
  6848. c=0;
  6849. loc = strstr(payload, "connectorId");
  6850. memset(sstr ,0, sizeof(sstr) );
  6851. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6852. {
  6853. sstr[c] = loc[strlen("connectorId")+2+c];
  6854. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6855. c++;
  6856. }
  6857. sstr[c] = '\0';
  6858. connectorIdInt = atoi(sstr);
  6859. //***(2)expiryDate ****/
  6860. loc = strstr(payload, "expiryDate");
  6861. memset(sstr ,0, sizeof(sstr) );
  6862. c = 0;
  6863. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6864. {
  6865. sstr[c] = loc[3+strlen("expiryDate")+c];
  6866. c++;
  6867. }
  6868. sstr[c] = '\0';
  6869. strcpy(expiryDatestr, sstr);
  6870. //***(3)idTag ****/
  6871. loc = strstr(payload, "idTag");
  6872. memset(sstr ,0, sizeof(sstr) );
  6873. c = 0;
  6874. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6875. {
  6876. sstr[c] = loc[3+strlen("idTag")+c];
  6877. c++;
  6878. }
  6879. sstr[c] = '\0';
  6880. strcpy(idTagstr, sstr);
  6881. //***(4)parentIdTag ****/
  6882. loc = strstr(payload, "parentIdTag");
  6883. memset(sstr ,0, sizeof(sstr) );
  6884. c = 0;
  6885. if(loc == NULL)
  6886. {
  6887. strcpy(parentIdTagstr, "");
  6888. }
  6889. else
  6890. {
  6891. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6892. {
  6893. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6894. c++;
  6895. }
  6896. sstr[c] = '\0';
  6897. strcpy(parentIdTagstr, sstr);
  6898. }
  6899. //***(5)reservationId ****/
  6900. c=0;
  6901. loc = strstr(payload, "reservationId");
  6902. memset(sstr ,0, sizeof(sstr) );
  6903. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6904. {
  6905. sstr[c] = loc[strlen("reservationId")+2+c];
  6906. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6907. c++;
  6908. }
  6909. sstr[c] = '\0';
  6910. reservationIdInt = atoi(sstr);
  6911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6912. if(reservationIdInt == 0)
  6913. {
  6914. //reservationId's value can not be 0
  6915. //strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6916. goto end;
  6917. }
  6918. /*
  6919. enum SYSTEM_STATUS
  6920. {
  6921. SYS_MODE_BOOTING = 0,
  6922. SYS_MODE_IDLE = 1,
  6923. SYS_MODE_AUTHORIZING = 2,
  6924. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6925. SYS_MODE_REASSIGN = 4,
  6926. SYS_MODE_PREPARING = 5,
  6927. SYS_MODE_PREPARE_FOR_EV = 6,
  6928. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6929. SYS_MODE_CHARGING = 8,
  6930. SYS_MODE_TERMINATING = 9,
  6931. SYS_MODE_COMPLETE = 10,
  6932. SYS_MODE_ALARM = 11,
  6933. SYS_MODE_FAULT = 12,
  6934. SYS_MODE_RESERVATION = 13,
  6935. SYS_MODE_BOOKING = 14,
  6936. SYS_MODE_MAINTAIN = 15,
  6937. SYS_MODE_DEBUG = 16,
  6938. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6939. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6940. SYS_MODE_UPDATE = 19
  6941. };
  6942. */
  6943. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6944. {
  6945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6946. goto end;
  6947. }
  6948. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6949. {
  6950. //check Transaction active
  6951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6952. {
  6953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6954. {
  6955. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6956. {
  6957. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6958. {
  6959. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6960. {
  6961. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6962. {
  6963. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6965. }
  6966. 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'))
  6967. {
  6968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6969. }
  6970. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  6971. {
  6972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6973. }
  6974. else
  6975. {
  6976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6977. }
  6978. }
  6979. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6980. {
  6981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6982. }
  6983. }
  6984. else
  6985. {
  6986. //replace reservation
  6987. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6989. }
  6990. }
  6991. } // END FOR CHAdeMO_QUANTITY
  6992. for (int index = 0; index < CCS_QUANTITY; index++)
  6993. {
  6994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6995. {
  6996. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6997. {
  6998. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6999. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7000. {
  7001. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7002. {
  7003. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7005. }
  7006. 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'))
  7007. {
  7008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7009. }
  7010. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7011. {
  7012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7013. }
  7014. else
  7015. {
  7016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7017. }
  7018. }
  7019. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7020. {
  7021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7022. }
  7023. }
  7024. else
  7025. {
  7026. //replace reservation
  7027. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7029. }
  7030. }
  7031. } // END FOR CCS_QUANTITY
  7032. for (int index = 0; index < GB_QUANTITY; index++)
  7033. {
  7034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7035. {
  7036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7037. {
  7038. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7039. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7040. {
  7041. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7042. {
  7043. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7045. }
  7046. 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'))
  7047. {
  7048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7049. }
  7050. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7051. {
  7052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7053. }
  7054. else
  7055. {
  7056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7057. }
  7058. }
  7059. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7060. {
  7061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7062. }
  7063. }
  7064. else
  7065. {
  7066. //replace reservation
  7067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7069. }
  7070. }
  7071. }// END FOR GB_QUANTITY
  7072. }
  7073. else
  7074. {
  7075. for (int index = 0; index < AC_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7078. {
  7079. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7080. {
  7081. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7082. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7083. {
  7084. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7085. {
  7086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7088. }
  7089. 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'))
  7090. {
  7091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7092. }
  7093. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7094. {
  7095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7096. }
  7097. else
  7098. {
  7099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7100. }
  7101. }
  7102. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7103. {
  7104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7105. }
  7106. }
  7107. else
  7108. {
  7109. //replace reservation
  7110. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7112. }
  7113. }
  7114. } // END FOR AC_QUANTITY
  7115. }//END FOR AC ELSE
  7116. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7117. }
  7118. else if(connectorIdInt == 0)
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7121. {
  7122. //check Transaction active
  7123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7124. {
  7125. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7126. {
  7127. 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'))
  7128. {
  7129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7130. goto end;
  7131. }
  7132. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7135. goto end;
  7136. }
  7137. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7138. {
  7139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7140. goto end;
  7141. }
  7142. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7143. {
  7144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7145. goto end;
  7146. }
  7147. }
  7148. }// END FOR CHAdeMO_QUANTITY
  7149. for (int index = 0; index < CCS_QUANTITY; index++)
  7150. {
  7151. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7152. {
  7153. 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'))
  7154. {
  7155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7156. }
  7157. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7158. {
  7159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7160. }
  7161. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7162. {
  7163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7164. }
  7165. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7166. {
  7167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7168. }
  7169. }
  7170. } // END FOR CCS_QUANTITY
  7171. for (int index = 0; index < GB_QUANTITY; index++)
  7172. {
  7173. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7174. {
  7175. 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'))
  7176. {
  7177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7178. }
  7179. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7180. {
  7181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7182. }
  7183. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7184. {
  7185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7186. }
  7187. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7188. {
  7189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7190. }
  7191. }
  7192. } // END FOR GB_QUANTITY
  7193. }
  7194. else
  7195. {
  7196. for (int index = 0; index < AC_QUANTITY; index++)
  7197. {
  7198. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7199. {
  7200. 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'))
  7201. {
  7202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7203. goto end;
  7204. }
  7205. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7206. {
  7207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7208. goto end;
  7209. }
  7210. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7211. {
  7212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7213. goto end;
  7214. }
  7215. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7216. {
  7217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7218. goto end;
  7219. }
  7220. }
  7221. }// END FOR AC_QUANTITY
  7222. }
  7223. //The connectorId is 0
  7224. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7226. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7227. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7228. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7229. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7230. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7231. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7232. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7233. result = TRUE;
  7234. return result;
  7235. }
  7236. else
  7237. {
  7238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7239. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7240. }
  7241. if(strcmp(comfirmstr,"Accepted") == 0)
  7242. {
  7243. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7244. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7245. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7246. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7247. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7248. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7249. result = TRUE;
  7250. return result;
  7251. }
  7252. end:
  7253. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7254. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7255. return result;
  7256. }
  7257. int handleResetRequest(char *uuid, char *payload)
  7258. {
  7259. mtrace();
  7260. int result = FAIL;
  7261. char sstr[10]={0};
  7262. char typestr[10]={0};
  7263. char comfirmstr[20]={0};
  7264. int c = 0;
  7265. char *loc;
  7266. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7267. DEBUG_INFO("handleResetRequest ...\n");
  7268. loc = strstr(payload, "type");
  7269. memset(sstr ,0, sizeof(sstr) );
  7270. c = 0;
  7271. while (loc[3+strlen("type")+c] != '\"')
  7272. {
  7273. sstr[c] = loc[3+strlen("type")+c];
  7274. c++;
  7275. }
  7276. sstr[c] = '\0';
  7277. strcpy(typestr,sstr);
  7278. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7279. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7280. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7281. {
  7282. //check Transaction active
  7283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7284. {
  7285. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7286. {
  7287. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7288. {
  7289. //0: unplug, 1: Plug-in
  7290. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7291. }
  7292. }
  7293. for (int index = 0; index < CCS_QUANTITY; index++)
  7294. {
  7295. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7296. {
  7297. //0: unplug, 1: Plug-in
  7298. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7299. }
  7300. }
  7301. for (int index = 0; index < GB_QUANTITY; index++)
  7302. {
  7303. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7304. {
  7305. //0: unplug, 1: Plug-in
  7306. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7307. }
  7308. }
  7309. }
  7310. else
  7311. {
  7312. for (int index = 0; index < AC_QUANTITY; index++)
  7313. {
  7314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7315. {
  7316. //0: unplug, 1: Plug-in
  7317. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7318. }
  7319. }
  7320. }// END FOR AC ELSE
  7321. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7322. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7323. result = TRUE;
  7324. return result;
  7325. }
  7326. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7327. {
  7328. //check Transaction active
  7329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7330. {
  7331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7332. {
  7333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7334. {
  7335. //0: unplug, 1: Plug-in
  7336. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7337. }
  7338. }
  7339. for (int index = 0; index < CCS_QUANTITY; index++)
  7340. {
  7341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7342. {
  7343. //0: unplug, 1: Plug-in
  7344. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7345. }
  7346. }
  7347. for (int index = 0; index < GB_QUANTITY; index++)
  7348. {
  7349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7350. {
  7351. //0: unplug, 1: Plug-in
  7352. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7353. }
  7354. }
  7355. }
  7356. else
  7357. {
  7358. for (int index = 0; index < AC_QUANTITY; index++)
  7359. {
  7360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7361. {
  7362. //0: unplug, 1: Plug-in
  7363. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7364. }
  7365. }
  7366. }// END FOR AC ELSE
  7367. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7368. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7369. result = TRUE;
  7370. return result;
  7371. }
  7372. else
  7373. {
  7374. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7375. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7376. goto errorend;
  7377. }
  7378. errorend:
  7379. sendResetConfirmation(uuid, comfirmstr);
  7380. return result;
  7381. }
  7382. int handleSendLocalListRequest(char *uuid, char *payload)
  7383. {
  7384. mtrace();
  7385. int result = FAIL;
  7386. int listVersionInt;
  7387. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7388. char listsearch[]="listVersion";
  7389. char updateTypesearch[]="updateType";
  7390. char localAuthorizationListsearch[]="localAuthorizationList";
  7391. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7392. char CardList[500][160]={0};
  7393. char updateTypestr[15]={0};
  7394. char idTagstr[20]={0};
  7395. char parentIdTag[20]={0};
  7396. char expiryDate[30]={0};
  7397. char idTagstatus[16]={0};
  7398. int c = 0;
  7399. int i = 0;
  7400. char *delim1 = "}";
  7401. char * pch;
  7402. char *loc;
  7403. //char *ptr;
  7404. char comfirmstr[20];
  7405. //int n_localAuthorizations = 0;
  7406. int checkState_Faulted = FALSE;
  7407. DEBUG_INFO("handleSendLocalListRequest\n");
  7408. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7409. {
  7410. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7411. goto end;
  7412. }
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7414. {
  7415. //check Charge Point state
  7416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7417. {
  7418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7419. {
  7420. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7421. }
  7422. }
  7423. for (int index = 0; index < CCS_QUANTITY; index++)
  7424. {
  7425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7426. {
  7427. checkState_Faulted = TRUE; //OCPP Status
  7428. }
  7429. }
  7430. for (int index = 0; index < GB_QUANTITY; index++)
  7431. {
  7432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7433. {
  7434. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7435. }
  7436. }
  7437. }
  7438. else
  7439. {
  7440. //check Charge Point state
  7441. for (int index = 0; index < AC_QUANTITY; index++)
  7442. {
  7443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7444. {
  7445. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7446. }
  7447. }
  7448. }// END FOR AC ELSE
  7449. if(checkState_Faulted == TRUE)
  7450. {
  7451. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7452. goto end;
  7453. }
  7454. //listVersion
  7455. c = 0;
  7456. loc = strstr(payload, listsearch);
  7457. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7458. {
  7459. sstr[c] = loc[strlen("listVersion")+2+c];
  7460. c++;
  7461. }
  7462. sstr[c] = '\0';
  7463. listVersionInt = atoi(sstr);
  7464. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7465. //updateType
  7466. loc = strstr(payload, updateTypesearch);
  7467. c = 0;
  7468. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7469. {
  7470. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7471. c++;
  7472. }
  7473. sstr[c] = '\0';
  7474. strcpy(updateTypestr, sstr);
  7475. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7476. //localAuthorizationList
  7477. memset(sstr ,0, sizeof(sstr) );
  7478. loc = strstr(payload, localAuthorizationListsearch);
  7479. if(loc != NULL) // localAuthorizationList is not NULL
  7480. {
  7481. //Check UpdateType
  7482. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7483. {
  7484. //Local list full update
  7485. printf("Local list full update.\n");
  7486. OCPP_getListVerion();
  7487. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7488. {
  7489. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7490. goto end;
  7491. }
  7492. OCPP_cleanLocalList();
  7493. }
  7494. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7495. {
  7496. //Local list different update
  7497. printf("Local list different update.\n");
  7498. OCPP_getListVerion();
  7499. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7500. {
  7501. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7502. goto end;
  7503. }
  7504. }
  7505. else
  7506. {
  7507. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7508. goto end;
  7509. }
  7510. c = 0;
  7511. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7512. {
  7513. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7515. c++;
  7516. }
  7517. sstr[c] = '\0';
  7518. //DEBUG_INFO("sstr=%s\n", sstr);
  7519. //parsing strings to words
  7520. i = 0;
  7521. pch = strtok(sstr,delim1);
  7522. while (pch != NULL)
  7523. {
  7524. strcpy(CardList[i], pch);
  7525. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7526. pch = strtok (NULL, delim1);
  7527. i = i + 1;
  7528. }
  7529. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7530. //local Authorizations List Numbers
  7531. //n_localAuthorizations = i;
  7532. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7533. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7534. c= 0;
  7535. while(c < i) // i is CardList Number
  7536. {
  7537. //Search "IdToken"
  7538. memset(sstr ,0, sizeof(sstr) );
  7539. loc = strstr(CardList[c], "idTag");
  7540. int j = 0;
  7541. while (loc[3+strlen("idTag")+j] != '\"')
  7542. {
  7543. sstr[j] = loc[3+strlen("idTag")+j];
  7544. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7545. j++;
  7546. }
  7547. sstr[j] = '\0';
  7548. strcpy(idTagstr, sstr);
  7549. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7550. //Search "expiryDate"
  7551. memset(sstr ,0, sizeof(sstr) );
  7552. loc = strstr(CardList[c], "expiryDate");
  7553. j = 0;
  7554. if(loc != NULL)
  7555. {
  7556. while (loc[3+strlen("expiryDate")+j] != '\"')
  7557. {
  7558. sstr[j] = loc[3+strlen("expiryDate")+j];
  7559. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7560. j++;
  7561. }
  7562. sstr[j] = '\0';
  7563. strcpy(expiryDate, sstr);
  7564. }
  7565. else
  7566. {
  7567. strcpy(expiryDate, "");
  7568. }
  7569. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7570. //Search "parentIdTag"
  7571. memset(sstr ,0, sizeof(sstr) );
  7572. loc = strstr(CardList[c], "parentIdTag");
  7573. j = 0;
  7574. if(loc != NULL)
  7575. {
  7576. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7577. {
  7578. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7579. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7580. j++;
  7581. }
  7582. sstr[j] = '\0';
  7583. strcpy(parentIdTag, sstr);
  7584. }
  7585. else
  7586. {
  7587. strcpy(parentIdTag, "");
  7588. }
  7589. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7590. //Search "status"
  7591. memset(sstr ,0, sizeof(sstr) );
  7592. loc = strstr(CardList[c], "status");
  7593. j = 0;
  7594. while (loc[3+strlen("status")+j] != '\"')
  7595. {
  7596. sstr[j] = loc[3+strlen("status")+j];
  7597. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7598. j++;
  7599. }
  7600. sstr[j] = '\0';
  7601. strcpy(idTagstatus, sstr);
  7602. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7603. OCPP_getIdTag(idTagstr);
  7604. //OCPP_getIdTag("test"); For Test
  7605. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7606. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7607. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7608. {
  7609. //Local list full update
  7610. DEBUG_INFO("Local list full update.\n");
  7611. // update list
  7612. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7613. //DEBUG_INFO("Local list full update. 1\n");
  7614. //OCPP_get_TableAuthlocalAllData();
  7615. //DEBUG_INFO("Local list full update. 2\n");
  7616. }
  7617. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7618. {
  7619. #if 0
  7620. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7621. {
  7622. //OCPP_deleteIdTag(idTagstr);
  7623. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7624. }
  7625. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7626. {
  7627. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7628. }
  7629. #endif
  7630. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7631. }
  7632. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7633. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7634. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7635. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7636. c++;
  7637. }
  7638. }
  7639. else
  7640. {
  7641. //Check UpdateType
  7642. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7643. {
  7644. //Local list full update
  7645. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7646. OCPP_cleanLocalList();
  7647. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7648. goto end;
  7649. }
  7650. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7651. {
  7652. //Local list different update
  7653. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7654. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7655. goto end;
  7656. }
  7657. }
  7658. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7659. end:
  7660. sendSendLocalListConfirmation(uuid, comfirmstr);
  7661. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7662. return result;
  7663. }
  7664. #define MAX 200
  7665. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7666. {
  7667. mtrace();
  7668. int result = FAIL;
  7669. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7670. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7671. char chargingProfilePurposeStr[30]={0};
  7672. char chargingProfileKindStr[16]={0};
  7673. char recurrencyKindStr[10]={0};
  7674. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7675. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7676. int chargingSchedulePeriodCount = 0;
  7677. //int updateflag = FALSE;
  7678. char comfirmstr[20]={0};
  7679. int meet= FALSE;
  7680. char sstr[10]={0};
  7681. int c = 0;
  7682. char *loc;
  7683. FILE *fptr1;//, *fptr2;
  7684. //int lno=0;//, linectr = 0;
  7685. //int modifyflag = FALSE;
  7686. char filename[MAX]={0};
  7687. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7688. //int resultRename=0;
  7689. char rmFileCmd[50]={0};
  7690. char tempchargingProfilePurposeStr[30]={0};
  7691. char word[1600]={0};
  7692. int n_chargingProfile = 0;
  7693. //[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}}}]
  7694. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7695. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7696. //*********************connectorId***************************/
  7697. loc = strstr(payload, "connectorId");
  7698. c = 0;
  7699. memset(sstr ,0, sizeof(sstr) );
  7700. while (loc[strlen("connectorId")+2+c] != ',')
  7701. {
  7702. sstr[c] = loc[strlen("connectorId")+2+c];
  7703. c++;
  7704. }
  7705. sstr[c] = '\0';
  7706. connectorIdInt = atoi(sstr);
  7707. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7708. {
  7709. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7710. }
  7711. else
  7712. {
  7713. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7714. }
  7715. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7716. //*********************chargingProfileId***************************/
  7717. loc = strstr(payload, "chargingProfileId");
  7718. c = 0;
  7719. memset(sstr ,0, sizeof(sstr) );
  7720. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7721. {
  7722. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7723. c++;
  7724. }
  7725. sstr[c] = '\0';
  7726. chargingProfileIdInt = atoi(sstr);
  7727. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7728. {
  7729. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7730. }
  7731. else
  7732. {
  7733. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7734. }
  7735. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7736. //*********************transactionId***************************/
  7737. loc = strstr(payload, "transactionId");
  7738. if(loc != NULL)
  7739. {
  7740. c = 0;
  7741. memset(sstr ,0, sizeof(sstr) );
  7742. while (loc[strlen("transactionId")+2+c] != ',')
  7743. {
  7744. sstr[c] = loc[strlen("transactionId")+2+c];
  7745. c++;
  7746. }
  7747. sstr[c] = '\0';
  7748. transactionIdInt = atoi(sstr);
  7749. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7750. {
  7751. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7752. }
  7753. else
  7754. {
  7755. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7756. }
  7757. }
  7758. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7759. //*********************stackLevel***************************/
  7760. loc = strstr(payload, "stackLevel");
  7761. c = 0;
  7762. memset(sstr ,0, sizeof(sstr) );
  7763. while (loc[strlen("stackLevel")+2+c] != ',')
  7764. {
  7765. sstr[c] = loc[strlen("stackLevel")+2+c];
  7766. c++;
  7767. }
  7768. sstr[c] = '\0';
  7769. stackLevelInt = atoi(sstr);
  7770. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7771. {
  7772. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7773. }
  7774. else
  7775. {
  7776. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7777. }
  7778. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7779. //*********************chargingProfilePurpose***************************/
  7780. loc = strstr(payload, "chargingProfilePurpose");
  7781. c = 0;
  7782. memset(sstr ,0, sizeof(sstr) );
  7783. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7784. {
  7785. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7787. c++;
  7788. }
  7789. sstr[c] = '\0';
  7790. strcpy(chargingProfilePurposeStr,sstr);
  7791. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7792. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7793. {
  7794. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7795. }
  7796. else
  7797. {
  7798. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7799. }
  7800. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7801. //*********************chargingProfileKind***************************/
  7802. loc = strstr(payload, "chargingProfileKind");
  7803. c = 0;
  7804. memset(sstr ,0, sizeof(sstr) );
  7805. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7806. {
  7807. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7809. c++;
  7810. }
  7811. sstr[c] = '\0';
  7812. strcpy(chargingProfileKindStr,sstr);
  7813. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7814. {
  7815. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7816. }
  7817. else
  7818. {
  7819. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7820. }
  7821. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7822. //*********************recurrencyKind***************************/
  7823. loc = strstr(payload, "recurrencyKind");
  7824. if(loc != NULL)
  7825. {
  7826. c = 0;
  7827. memset(sstr ,0, sizeof(sstr) );
  7828. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7829. {
  7830. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7832. c++;
  7833. }
  7834. sstr[c] = '\0';
  7835. strcpy(recurrencyKindStr,sstr);
  7836. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7837. {
  7838. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7839. }
  7840. else
  7841. {
  7842. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7843. }
  7844. }
  7845. else
  7846. {
  7847. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7848. {
  7849. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7850. }
  7851. else
  7852. {
  7853. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7854. }
  7855. }
  7856. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7857. //*********************validFrom***************************/
  7858. loc = strstr(payload, "validFrom");
  7859. if(loc != NULL)
  7860. {
  7861. c = 0;
  7862. memset(sstr ,0, sizeof(sstr) );
  7863. while (loc[3+strlen("validFrom")+c] != '\"')
  7864. {
  7865. sstr[c] = loc[3+strlen("validFrom")+c];
  7866. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7867. c++;
  7868. }
  7869. sstr[c] = '\0';
  7870. strcpy(validFromStr,sstr);
  7871. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7872. {
  7873. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7874. }
  7875. else
  7876. {
  7877. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7878. }
  7879. }
  7880. else
  7881. {
  7882. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7883. {
  7884. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7885. }
  7886. else
  7887. {
  7888. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7889. }
  7890. }
  7891. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7892. //*********************validTo***************************/
  7893. loc = strstr(payload, "validTo");
  7894. if(loc != NULL)
  7895. {
  7896. c = 0;
  7897. memset(sstr ,0, sizeof(sstr) );
  7898. while (loc[3+strlen("validTo")+c] != '\"')
  7899. {
  7900. sstr[c] = loc[3+strlen("validTo")+c];
  7901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7902. c++;
  7903. }
  7904. sstr[c] = '\0';
  7905. strcpy(validToStr,sstr);
  7906. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7907. {
  7908. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7909. }
  7910. else
  7911. {
  7912. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7913. }
  7914. }
  7915. else
  7916. {
  7917. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7918. {
  7919. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7920. }
  7921. else
  7922. {
  7923. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7924. }
  7925. }
  7926. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7927. //*********************duration***************************/
  7928. loc = strstr(payload, "duration");
  7929. if(loc != NULL)
  7930. {
  7931. c = 0;
  7932. memset(sstr ,0, sizeof(sstr) );
  7933. while (loc[strlen("duration")+2+c] != ',')
  7934. {
  7935. sstr[c] = loc[strlen("duration")+2+c];
  7936. c++;
  7937. }
  7938. sstr[c] = '\0';
  7939. durationInt = atoi(sstr);
  7940. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7941. {
  7942. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7943. }
  7944. else
  7945. {
  7946. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7947. }
  7948. }
  7949. else
  7950. {
  7951. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7952. {
  7953. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7954. }
  7955. else
  7956. {
  7957. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7958. }
  7959. }
  7960. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7961. //*********************startSchedule***************************/
  7962. loc = strstr(payload, "startSchedule");
  7963. if(loc != NULL)
  7964. {
  7965. c = 0;
  7966. memset(sstr ,0, sizeof(sstr) );
  7967. while (loc[3+strlen("startSchedule")+c] != '\"')
  7968. {
  7969. sstr[c] = loc[3+strlen("startSchedule")+c];
  7970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7971. c++;
  7972. }
  7973. sstr[c] = '\0';
  7974. strcpy(startScheduleStr,sstr);
  7975. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7976. {
  7977. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7978. }
  7979. else
  7980. {
  7981. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7982. }
  7983. }
  7984. else
  7985. {
  7986. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7987. {
  7988. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7989. }
  7990. else
  7991. {
  7992. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7993. }
  7994. }
  7995. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7996. //*********************chargingRateUnit***************************/
  7997. loc = strstr(payload, "chargingRateUnit");
  7998. if(loc != NULL)
  7999. {
  8000. c = 0;
  8001. memset(sstr ,0, sizeof(sstr) );
  8002. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8003. {
  8004. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8006. c++;
  8007. }
  8008. sstr[c] = '\0';
  8009. strcpy(chargingRateUnitStr,sstr);
  8010. #if 0
  8011. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8012. {
  8013. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8014. goto end;
  8015. }
  8016. #endif
  8017. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8018. {
  8019. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8020. }
  8021. else
  8022. {
  8023. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8024. }
  8025. }
  8026. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8027. //****************chargingSchedulePeriod count start*******************/
  8028. int what_len = strlen("startPeriod");
  8029. char tempChargingProfile[1000]={0};
  8030. strcpy(tempChargingProfile,(const char*)payload);
  8031. char *where = tempChargingProfile;
  8032. if (what_len)
  8033. {
  8034. while ((where = strstr(where, "startPeriod"))) {
  8035. where += what_len;
  8036. chargingSchedulePeriodCount++;
  8037. }
  8038. }
  8039. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8040. {
  8041. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8042. goto end;
  8043. }
  8044. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8045. //where = payload;
  8046. int templength = 0;
  8047. //int searchstart = 0;
  8048. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8049. {
  8050. //****************startPeriod*******************/
  8051. c=0;
  8052. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8053. memset(sstr ,0, sizeof(sstr) );
  8054. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8055. {
  8056. sstr[c] = loc[strlen("startPeriod")+2+c];
  8057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8058. c++;
  8059. }
  8060. sstr[c] = '\0';
  8061. startPeriodInt[periodNums] = atoi(sstr);
  8062. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8063. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8064. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8065. {
  8066. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8067. }
  8068. else
  8069. {
  8070. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8071. }
  8072. templength = strlen("startPeriod")+2+c;
  8073. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8074. //****************limit*******************/
  8075. c=0;
  8076. loc = strstr(tempChargingProfile + templength, "limit");
  8077. memset(sstr ,0, sizeof(sstr) );
  8078. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8079. {
  8080. sstr[c] = loc[strlen("limit")+2+c];
  8081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8082. c++;
  8083. }
  8084. sstr[c] = '\0';
  8085. limitflaot[periodNums] = atof(sstr);
  8086. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8087. {
  8088. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8089. }
  8090. else
  8091. {
  8092. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8093. }
  8094. templength = templength + strlen("limit")+2+c;
  8095. //****************numberPhases*******************/
  8096. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8097. if(loc != NULL)
  8098. {
  8099. c=0;
  8100. memset(sstr ,0, sizeof(sstr) );
  8101. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8102. {
  8103. sstr[c] = loc[strlen("numberPhases")+2+c];
  8104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8105. c++;
  8106. }
  8107. sstr[c] = '\0';
  8108. numberPhasesInt[periodNums] = atoi(sstr);
  8109. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8110. {
  8111. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8112. }
  8113. else
  8114. {
  8115. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8116. }
  8117. templength = templength + strlen("numberPhases")+2+c;
  8118. }
  8119. //where = loc;
  8120. }
  8121. //****************chargingSchedulePeriod count end*******************/
  8122. //*********************minChargingRate***************************/
  8123. loc = strstr(payload, "minChargingRate");
  8124. if(loc != NULL)
  8125. {
  8126. c = 0;
  8127. memset(sstr ,0, sizeof(sstr) );
  8128. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8129. {
  8130. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8131. c++;
  8132. }
  8133. sstr[c] = '\0';
  8134. minChargingRateFloat = atof(sstr);
  8135. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8136. {
  8137. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8138. }
  8139. else
  8140. {
  8141. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8142. }
  8143. }
  8144. else
  8145. {
  8146. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8147. {
  8148. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8149. }
  8150. else
  8151. {
  8152. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8153. }
  8154. }
  8155. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8156. {
  8157. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8158. if(connectorIdInt != 0)
  8159. {
  8160. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8161. goto end;
  8162. }
  8163. strcpy(filename, ChargePointMaxProfile_JSON );
  8164. fptr1 = fopen(filename, "r");
  8165. if (!fptr1)
  8166. {
  8167. //file not exist
  8168. DEBUG_INFO("Unable to open the input file!!\n");
  8169. fptr1 = fopen(filename, "w+");
  8170. }
  8171. else
  8172. {
  8173. //Check Charging Profile Count
  8174. while(fscanf(fptr1, "%s", word) != EOF)
  8175. {
  8176. //DEBUG_INFO("word=%s\n",word);
  8177. if(strstr(word, "chargingProfileId")!= NULL)
  8178. {
  8179. //DEBUG_INFO("test chargingProfileId \n");
  8180. n_chargingProfile = n_chargingProfile + 1;
  8181. //DEBUG_INFO("chargingProfileId Found\n");
  8182. }
  8183. }
  8184. }
  8185. fclose(fptr1);
  8186. }
  8187. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8188. {
  8189. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8190. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8191. {
  8192. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8193. goto end;
  8194. }
  8195. #if 0
  8196. switch(connectorIdInt)
  8197. {
  8198. case 0:
  8199. strcpy(filename, TxDefaultProfile_0_JSON );
  8200. break;
  8201. case 1:
  8202. strcpy(filename, TxDefaultProfile_1_JSON );
  8203. break;
  8204. case 2:
  8205. strcpy(filename, TxDefaultProfile_2_JSON );
  8206. break;
  8207. default:
  8208. strcpy(filename, TxDefaultProfile_0_JSON );
  8209. break;
  8210. }
  8211. #endif
  8212. memset(filename, 0, sizeof filename);
  8213. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8214. fptr1 = fopen(filename, "r");
  8215. if (!fptr1)
  8216. {
  8217. //file not exist
  8218. //DEBUG_INFO("Unable to open the input file!!\n");
  8219. fptr1 = fopen(filename, "w+");
  8220. }
  8221. else
  8222. {
  8223. //Check Charging Profile Count
  8224. while(fscanf(fptr1, "%s", word) != EOF)
  8225. {
  8226. //DEBUG_INFO("word=%s\n",word);
  8227. if(strstr(word, "chargingProfileId")!= NULL)
  8228. {
  8229. //DEBUG_INFO("test chargingProfileId \n");
  8230. n_chargingProfile = n_chargingProfile + 1;
  8231. //DEBUG_INFO("chargingProfileId Found\n");
  8232. }
  8233. }
  8234. }
  8235. fclose(fptr1);
  8236. }
  8237. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8238. {
  8239. //printf("set chargingProfile 1-4\n");
  8240. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8241. //check Transaction active
  8242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8243. {
  8244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8245. {
  8246. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8247. {
  8248. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8249. {
  8250. meet = TRUE;
  8251. break;
  8252. }
  8253. }
  8254. }
  8255. }
  8256. for (int index = 0; index < CCS_QUANTITY; index++)
  8257. {
  8258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8259. {
  8260. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8261. {
  8262. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8263. {
  8264. meet = TRUE;
  8265. break;
  8266. }
  8267. }
  8268. }
  8269. }
  8270. for (int index = 0; index < GB_QUANTITY; index++)
  8271. {
  8272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8273. {
  8274. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8275. {
  8276. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8277. {
  8278. meet = TRUE;
  8279. break;
  8280. }
  8281. }
  8282. }
  8283. }
  8284. if(meet == FALSE)
  8285. {
  8286. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8287. goto end;
  8288. }
  8289. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8290. {
  8291. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8292. goto end;
  8293. }
  8294. #if 0
  8295. switch(connectorIdInt)
  8296. {
  8297. case 0:
  8298. break;
  8299. case 1:
  8300. strcpy(filename, TxProfile_1_JSON);
  8301. break;
  8302. case 2:
  8303. strcpy(filename, TxProfile_2_JSON);
  8304. break;
  8305. default:
  8306. strcpy(filename, TxProfile_1_JSON);
  8307. break;
  8308. }
  8309. #endif
  8310. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8311. fptr1 = fopen(filename, "r");
  8312. if (!fptr1)
  8313. {
  8314. //file not exist
  8315. DEBUG_INFO("Unable to open the input file!!\n");
  8316. fptr1 = fopen(filename, "w+");
  8317. }
  8318. else
  8319. {
  8320. //Check Charging Profile Count
  8321. while(fscanf(fptr1, "%s", word) != EOF)
  8322. {
  8323. //DEBUG_INFO("word=%s\n",word);
  8324. if(strstr(word, "chargingProfileId")!= NULL)
  8325. {
  8326. //DEBUG_INFO("test chargingProfileId \n");
  8327. n_chargingProfile = n_chargingProfile + 1;
  8328. //DEBUG_INFO("chargingProfileId Found\n");
  8329. }
  8330. }
  8331. }
  8332. fclose(fptr1);
  8333. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8334. }
  8335. // Check ChargeProfileMaxStackLevel
  8336. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8337. {
  8338. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8339. goto end;
  8340. }
  8341. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8342. {
  8343. int i = 0;
  8344. char fnametemp[200]={0};
  8345. n_chargingProfile = 0;
  8346. //Check ChargePointMaxProfile.json exit
  8347. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8348. {
  8349. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8350. //Check Charging Profile Count
  8351. while(fscanf(fptr1, "%s", word) != EOF)
  8352. {
  8353. //DEBUG_INFO("word=%s\n",word);
  8354. if(strstr(word, "chargingProfileId")!= NULL)
  8355. {
  8356. //DEBUG_INFO("test chargingProfileId \n");
  8357. n_chargingProfile = n_chargingProfile + 1;
  8358. i = i + 1;
  8359. //DEBUG_INFO("chargingProfileId Found\n");
  8360. }
  8361. memset(word, 0, sizeof word);
  8362. }
  8363. fclose(fptr1);
  8364. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8365. }
  8366. //Check TxDefaultProfile_0.json exit
  8367. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8368. {
  8369. i = 0;
  8370. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8371. //Check Charging Profile Count
  8372. while(fscanf(fptr1, "%s", word) != EOF)
  8373. {
  8374. //DEBUG_INFO("word=%s\n",word);
  8375. if(strstr(word, "chargingProfileId")!= NULL)
  8376. {
  8377. //DEBUG_INFO("test chargingProfileId \n");
  8378. n_chargingProfile = n_chargingProfile + 1;
  8379. i = i + 1;
  8380. //DEBUG_INFO("chargingProfileId Found\n");
  8381. }
  8382. memset(word, 0, sizeof word);
  8383. }
  8384. fclose(fptr1);
  8385. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8386. }
  8387. //Check TxDefaultProfile_%d.json
  8388. for(int j=1; j <= gunTotalNumber; j++)
  8389. {
  8390. memset(fnametemp, 0, sizeof fnametemp);
  8391. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8392. if((access(fnametemp,F_OK))!=-1)
  8393. {
  8394. i = 0;
  8395. fptr1 = fopen(fnametemp, "r");
  8396. //Check Charging Profile Count
  8397. while(fscanf(fptr1, "%s", word) != EOF)
  8398. {
  8399. //DEBUG_INFO("word=%s\n",word);
  8400. if(strstr(word, "chargingProfileId")!= NULL)
  8401. {
  8402. //DEBUG_INFO("test chargingProfileId \n");
  8403. n_chargingProfile = n_chargingProfile + 1;
  8404. i = i + 1;
  8405. //DEBUG_INFO("chargingProfileId Found\n");
  8406. }
  8407. memset(word, 0, sizeof word);
  8408. }
  8409. fclose(fptr1);
  8410. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8411. }
  8412. }
  8413. //Check TxProfile_%d.json
  8414. for(int j=1; j <= gunTotalNumber; j++)
  8415. {
  8416. memset(fnametemp, 0, sizeof fnametemp);
  8417. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8418. if((access(fnametemp,F_OK))!=-1)
  8419. {
  8420. i = 0;
  8421. fptr1 = fopen(fnametemp, "r");
  8422. //Check Charging Profile Count
  8423. while(fscanf(fptr1, "%s", word) != EOF)
  8424. {
  8425. //DEBUG_INFO("word=%s\n",word);
  8426. if(strstr(word, "chargingProfileId")!= NULL)
  8427. {
  8428. //DEBUG_INFO("test chargingProfileId \n");
  8429. n_chargingProfile = n_chargingProfile + 1;
  8430. i = i + 1;
  8431. //DEBUG_INFO("chargingProfileId Found\n");
  8432. }
  8433. memset(word, 0, sizeof word);
  8434. }
  8435. fclose(fptr1);
  8436. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8437. }
  8438. }
  8439. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8440. {
  8441. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8442. goto end;
  8443. }
  8444. }
  8445. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8446. //**********************************Write to File********************************************************/
  8447. FILE *infile;
  8448. FILE *outfile;
  8449. // open file for writing
  8450. infile = fopen (filename, "r");
  8451. outfile = fopen (tempfile, "w");
  8452. int d =0;
  8453. d = fgetc(infile);
  8454. //DEBUG_INFO("d:%d\n",d);
  8455. rewind(infile);
  8456. //*检测到文件结束标识返回1,否则返回0。*/
  8457. if(d == EOF)
  8458. {
  8459. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8460. fprintf(outfile,"%s\n",payload);
  8461. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8462. fclose(infile);
  8463. fclose(outfile);
  8464. sprintf(rmFileCmd,"rm -f %s",filename);
  8465. system(rmFileCmd);
  8466. rename(tempfile, filename);
  8467. #if 0
  8468. resultRename = rename(tempfile, filename);
  8469. if(resultRename == 0)
  8470. {
  8471. DEBUG_INFO("File chargingProfile renamed successfully");
  8472. }
  8473. else
  8474. {
  8475. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8476. }
  8477. #endif
  8478. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8479. //system(rmFileCmd);
  8480. }
  8481. else
  8482. {
  8483. char buf[1000]={0};
  8484. int ChargingProfileAdded = FALSE;
  8485. while (fgets(buf, sizeof(buf), infile) != NULL)
  8486. {
  8487. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8488. //*************************tempconnectorIdInt*********************************/
  8489. loc = strstr(buf, "connectorId");
  8490. c = 0;
  8491. memset(sstr ,0, sizeof(sstr) );
  8492. while (loc[strlen("connectorId")+2+c] != ',')
  8493. {
  8494. sstr[c] = loc[strlen("connectorId")+2+c];
  8495. c++;
  8496. }
  8497. sstr[c] = '\0';
  8498. tempconnectorIdInt = atoi(sstr);
  8499. //*************************tempchargingProfileIdInt*********************************/
  8500. loc = strstr(buf, "chargingProfileId");
  8501. c = 0;
  8502. memset(sstr ,0, sizeof(sstr) );
  8503. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8504. {
  8505. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8506. c++;
  8507. }
  8508. sstr[c] = '\0';
  8509. tempchargingProfileIdInt = atoi(sstr);
  8510. //*************************tempstackLevelInt*********************************/
  8511. loc = strstr(buf, "stackLevel");
  8512. c = 0;
  8513. memset(sstr ,0, sizeof(sstr) );
  8514. while (loc[strlen("stackLevel")+2+c] != ',')
  8515. {
  8516. sstr[c] = loc[strlen("stackLevel")+2+c];
  8517. c++;
  8518. }
  8519. sstr[c] = '\0';
  8520. tempstackLevelInt = atoi(sstr);
  8521. //*************************tempchargingProfilePurposeStr*********************************/
  8522. loc = strstr(payload, "chargingProfilePurpose");
  8523. c = 0;
  8524. memset(sstr ,0, sizeof(sstr) );
  8525. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8526. {
  8527. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8528. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8529. c++;
  8530. }
  8531. sstr[c] = '\0';
  8532. strcpy(tempchargingProfilePurposeStr,sstr);
  8533. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8534. {
  8535. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8536. {
  8537. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8538. if(ChargingProfileAdded == FALSE)
  8539. {
  8540. fprintf(outfile,"%s\n",payload);
  8541. ChargingProfileAdded = TRUE;
  8542. }
  8543. }
  8544. else
  8545. {
  8546. if(tempstackLevelInt < stackLevelInt)
  8547. {
  8548. if(ChargingProfileAdded == FALSE)
  8549. {
  8550. fprintf(outfile,"%s\n",payload);
  8551. ChargingProfileAdded = TRUE;
  8552. fprintf(outfile,"%s\n",buf);
  8553. }
  8554. else
  8555. {
  8556. fprintf(outfile,"%s\n",buf);
  8557. }
  8558. }
  8559. else
  8560. {
  8561. if(ChargingProfileAdded == FALSE)
  8562. {
  8563. fprintf(outfile,"%s\n",buf);
  8564. fprintf(outfile,"%s\n",payload);
  8565. ChargingProfileAdded = TRUE;
  8566. }
  8567. else
  8568. {
  8569. fprintf(outfile,"%s\n",buf);
  8570. }
  8571. }
  8572. }
  8573. }
  8574. else
  8575. {
  8576. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8577. {
  8578. if(ChargingProfileAdded == FALSE)
  8579. {
  8580. fprintf(outfile,"%s\n",payload);
  8581. ChargingProfileAdded = TRUE;
  8582. fprintf(outfile,"%s\n",buf);
  8583. }
  8584. else
  8585. {
  8586. fprintf(outfile,"%s\n",buf);
  8587. }
  8588. }
  8589. else if(tempstackLevelInt < stackLevelInt)
  8590. {
  8591. if(ChargingProfileAdded == FALSE)
  8592. {
  8593. fprintf(outfile,"%s\n",payload);
  8594. ChargingProfileAdded = TRUE;
  8595. fprintf(outfile,"%s\n",buf);
  8596. }
  8597. else
  8598. {
  8599. fprintf(outfile,"%s\n",buf);
  8600. }
  8601. }
  8602. else
  8603. {
  8604. if(ChargingProfileAdded == FALSE)
  8605. {
  8606. fprintf(outfile,"%s\n",buf);
  8607. fprintf(outfile,"%s\n",payload);
  8608. ChargingProfileAdded = TRUE;
  8609. }
  8610. else
  8611. {
  8612. fprintf(outfile,"%s\n",buf);
  8613. }
  8614. }
  8615. }
  8616. } // end of while loop
  8617. fclose(infile);
  8618. fclose(outfile);
  8619. sprintf(rmFileCmd,"rm -f %s",filename);
  8620. system(rmFileCmd);
  8621. rename(tempfile, filename);
  8622. #if 0
  8623. resultRename = rename(tempfile, filename);
  8624. if(resultRename == 0)
  8625. {
  8626. DEBUG_INFO("File chargingProfile renamed successfully");
  8627. }
  8628. else
  8629. {
  8630. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8631. }
  8632. #endif
  8633. result = TRUE;
  8634. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8635. }
  8636. end:
  8637. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8638. return result;
  8639. return result;
  8640. }
  8641. int handleTriggerMessageRequest(char *uuid, char *payload)
  8642. {
  8643. mtrace();
  8644. int result = FAIL;
  8645. int connectorIdIsNULL = FALSE;
  8646. int connectorIdInt =0;
  8647. char sstr[40]={0};
  8648. char requestedMessagestr[40]={0};
  8649. char comfirmstr[20]={0};
  8650. int c = 0;
  8651. char *loc;
  8652. DEBUG_INFO("handleTriggerMessageRequest\n");
  8653. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8654. c = 0;
  8655. loc = strstr(payload, "requestedMessage");
  8656. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8657. {
  8658. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8659. c++;
  8660. }
  8661. sstr[c] = '\0';
  8662. strcpy(requestedMessagestr, sstr);
  8663. c = 0;
  8664. loc = strstr(payload, "connectorId");
  8665. if(loc == NULL)
  8666. {
  8667. connectorIdIsNULL = TRUE;
  8668. }
  8669. else
  8670. {
  8671. memset(sstr ,0, sizeof(sstr) );
  8672. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8673. {
  8674. sstr[c] = loc[strlen("connectorId")+2+c];
  8675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8676. c++;
  8677. }
  8678. sstr[c] = '\0';
  8679. connectorIdInt = atoi(sstr);
  8680. }
  8681. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8682. {
  8683. //connectorIdInt = json_object_get_int(connectorId);
  8684. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8685. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8686. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8687. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8688. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8689. }
  8690. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8691. {
  8692. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8693. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8694. return TRUE;
  8695. }
  8696. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8697. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8698. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8699. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8700. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8701. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8702. {
  8703. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8704. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8705. return TRUE;
  8706. }
  8707. else
  8708. {
  8709. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8710. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8711. }
  8712. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8713. {
  8714. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8715. {
  8716. FirmwareStatusNotificationStatus = 3;
  8717. }
  8718. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8719. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8720. }
  8721. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8722. {
  8723. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8724. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8725. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8726. }
  8727. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8728. {
  8729. sendBootNotificationRequest();
  8730. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8731. }
  8732. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8733. {
  8734. sendHeartbeatRequest(connectorIdInt);
  8735. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8736. }
  8737. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8738. {
  8739. if(connectorIdIsNULL == FALSE)
  8740. {
  8741. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8742. {
  8743. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8744. sendMeterValuesRequest(connectorIdInt -1);
  8745. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8746. }
  8747. }
  8748. else
  8749. {
  8750. for(int idx=0;idx< gunTotalNumber;idx++)
  8751. {
  8752. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8753. sendMeterValuesRequest(idx);
  8754. }
  8755. }
  8756. }
  8757. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8758. {
  8759. if(connectorIdIsNULL == FALSE)
  8760. {
  8761. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8762. {
  8763. sendStatusNotificationRequest(connectorIdInt -1);
  8764. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8765. }
  8766. }
  8767. else
  8768. {
  8769. for(int idx=0;idx< gunTotalNumber;idx++)
  8770. sendStatusNotificationRequest(idx);
  8771. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8772. }
  8773. }
  8774. return result;
  8775. }
  8776. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8777. {
  8778. mtrace();
  8779. int result = FAIL;
  8780. char sstr[6]={0};
  8781. int connectorIdInt =0;
  8782. char comfirmstr[20]={0};
  8783. int c = 0;
  8784. char *loc;
  8785. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8786. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8787. c = 0;
  8788. loc = strstr(payload, "connectorId");
  8789. memset(sstr ,0, sizeof(sstr) );
  8790. while (loc[strlen("connectorId")+2+c] != '}')
  8791. {
  8792. sstr[c] = loc[strlen("connectorId")+2+c];
  8793. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8794. c++;
  8795. }
  8796. sstr[c] = '\0';
  8797. connectorIdInt = atoi(sstr);
  8798. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8799. if(gunTotalNumber == 0)
  8800. {
  8801. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8802. goto end;
  8803. }
  8804. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8805. {
  8806. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8807. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8808. goto end;
  8809. }
  8810. else
  8811. {
  8812. //check Transaction active
  8813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8814. {
  8815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8816. {
  8817. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8818. {
  8819. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8820. }
  8821. }
  8822. for (int index = 0; index < CCS_QUANTITY; index++)
  8823. {
  8824. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8825. {
  8826. //stop Transaction
  8827. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8828. }
  8829. }
  8830. for (int index = 0; index < GB_QUANTITY; index++)
  8831. {
  8832. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8833. {
  8834. //stop Transaction
  8835. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8836. }
  8837. }
  8838. }
  8839. else
  8840. {
  8841. for (int index = 0; index < AC_QUANTITY; index++)
  8842. {
  8843. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8844. {
  8845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8846. }
  8847. }
  8848. }// END FOR AC ELSE
  8849. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8850. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8851. result = TRUE;
  8852. return result;
  8853. }
  8854. end:
  8855. //json_object_put(obj); --- remove temporally
  8856. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8857. return result;
  8858. }
  8859. static char UpdateFirmwarepayloadData[300]={0};
  8860. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8861. {
  8862. mtrace();
  8863. int result = FAIL;
  8864. pthread_t t;
  8865. sendUpdateFirmwareConfirmation(uuid);
  8866. memset(UpdateFirmwarepayloadData, 0, 300);
  8867. strcpy(UpdateFirmwarepayloadData, payload);
  8868. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8869. ////pthread_join(t, NULL); //
  8870. //pthread_detach(t);
  8871. //sendUpdateFirmwareConfirmation(uuid);
  8872. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8873. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8874. return result;
  8875. }
  8876. void *UpdateFirmwareProcess(void *data)
  8877. {
  8878. pthread_detach(pthread_self());
  8879. mtrace();
  8880. int retriesInt =0, retryIntervalInt=0;
  8881. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8882. int port=0;
  8883. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8884. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8885. //char comfirmstr[20];
  8886. int isSuccess = 0;
  8887. char ftpbuf[200];
  8888. char temp[100];
  8889. char * pch;
  8890. int retriesISNULL=FALSE;
  8891. int retryInterval=FALSE;
  8892. int c = 0;
  8893. //int i = 0;
  8894. char *loc;
  8895. char sstr[300]={ 0 };
  8896. char str[300]={ 0 };
  8897. //char *str = (char*) data; // ? ?輸入資 ?
  8898. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8899. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8900. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8901. //***************location **************/
  8902. loc = strstr(str, "location");
  8903. memset(sstr ,0, sizeof(sstr) );
  8904. c = 0;
  8905. while (loc[3+strlen("location")+c] != '\"')
  8906. {
  8907. sstr[c] = loc[3+strlen("location")+c];
  8908. c++;
  8909. }
  8910. sstr[c] = '\0';
  8911. strcpy(locationstr, sstr);
  8912. //***************retries**************/
  8913. c = 0;
  8914. loc = strstr(str, "retries");
  8915. if(loc == NULL)
  8916. {
  8917. retriesISNULL=TRUE;
  8918. }
  8919. else
  8920. {
  8921. memset(sstr ,0, sizeof(sstr) );
  8922. while (loc[strlen("retries")+2+c] != ',')
  8923. {
  8924. sstr[c] = loc[strlen("retries")+2+c];
  8925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8926. c++;
  8927. }
  8928. sstr[c] = '\0';
  8929. }
  8930. if(retriesISNULL == FALSE)
  8931. {
  8932. retriesInt = atoi(sstr);
  8933. }
  8934. //***************retrieveDate **************/
  8935. loc = strstr(str, "retrieveDate");
  8936. memset(sstr ,0, sizeof(sstr) );
  8937. c = 0;
  8938. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8939. {
  8940. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8941. c++;
  8942. }
  8943. sstr[c] = '\0';
  8944. strcpy(retrieveDatestr, sstr);
  8945. //***************retryInterval **************/
  8946. c = 0;
  8947. loc = strstr(str, "retryInterval");
  8948. memset(sstr ,0, sizeof(sstr) );
  8949. if(loc == NULL)
  8950. {
  8951. retryInterval=TRUE;
  8952. }
  8953. else
  8954. {
  8955. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8956. {
  8957. sstr[c] = loc[strlen("retryInterval")+2+c];
  8958. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8959. c++;
  8960. }
  8961. sstr[c] = '\0';
  8962. }
  8963. if(retryInterval==FALSE)
  8964. {
  8965. retryIntervalInt = atoi(sstr);
  8966. }
  8967. memset(ftppath, 0, sizeof(ftppath));
  8968. memset(path, 0, sizeof(path));
  8969. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8970. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8971. if(strncmp(locationstr,"http", 4) == 0)
  8972. {
  8973. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8974. protocol, host, path);
  8975. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8976. // protocol, user, password, host, path);
  8977. sprintf(ftppath,"/%s", path);
  8978. //DEBUG_INFO("protocol =%s\n",protocol);
  8979. //DEBUG_INFO("host =%s\n",host);
  8980. //DEBUG_INFO("path =%s\n",path);
  8981. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8982. int ftppathlen=strlen(ftppath);
  8983. int i=1;
  8984. char filenametemp[50];
  8985. while(i < ftppathlen)
  8986. {
  8987. int len=ftppathlen-i;
  8988. if(ftppath[len]== 47) // '/' ascll code: 47
  8989. {
  8990. DEBUG_INFO("compare '/' all right\n");
  8991. break;
  8992. }
  8993. i=i+1;
  8994. }
  8995. memset(filenametemp, 0, sizeof(filenametemp));
  8996. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8997. filenametemp[i+1] = 0;
  8998. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8999. do{
  9000. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9001. sleep(retryIntervalInt);
  9002. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9003. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9004. if(!isSuccess)
  9005. {
  9006. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9007. }
  9008. else
  9009. {
  9010. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9011. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9012. isUpdateRequest = TRUE;
  9013. }
  9014. }
  9015. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9016. {
  9017. memset(ftpbuf, 0, sizeof(ftpbuf));
  9018. memset(temp, 0, sizeof(temp));
  9019. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9020. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9021. int ftppathlen=strlen(ftpbuf);
  9022. int i=1;
  9023. char filenametemp[50];
  9024. while(i < ftppathlen)
  9025. {
  9026. int len=ftppathlen-i;
  9027. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9028. {
  9029. DEBUG_INFO(" compare '/' all right\n");
  9030. break;
  9031. }
  9032. i=i+1;
  9033. }
  9034. memset(filenametemp, 0, sizeof(filenametemp));
  9035. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9036. filenametemp[i+1] = 0;
  9037. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9038. pch=strchr(temp,'@');
  9039. if(pch==NULL)
  9040. {
  9041. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9042. protocol, host, &port, path);
  9043. strcpy(user,"anonymous");
  9044. strcpy(password,"");
  9045. }
  9046. else
  9047. {
  9048. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9049. protocol, user, password, host, &port, path);
  9050. }
  9051. sscanf(host,"%[^/]%s",host1, path1);
  9052. sprintf(ftppath,"%s", path1);
  9053. //DEBUG_INFO("protocol =%s\n",protocol);
  9054. //DEBUG_INFO("user =%s\n",user);
  9055. //DEBUG_INFO("password =%s\n",password);
  9056. //DEBUG_INFO("host1 =%s\n",host1);
  9057. //DEBUG_INFO("port =%d\n",port);
  9058. //DEBUG_INFO("path1 =%s\n",path1);
  9059. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9060. //ftpFile(host, user, password, port, ftppath, fname);
  9061. //download firmware pthred
  9062. if(port == 0)
  9063. {
  9064. port = 21;
  9065. }
  9066. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9067. do{
  9068. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9069. sleep(retryIntervalInt);
  9070. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9071. if(!isSuccess)
  9072. {
  9073. //BulldogUtil.sleepMs(interval*1000);
  9074. DEBUG_INFO("Update firmware request and download file fail.\n");
  9075. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9076. }
  9077. else
  9078. {
  9079. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9080. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9081. isUpdateRequest = TRUE;
  9082. }
  9083. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9084. }
  9085. else
  9086. {
  9087. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9088. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9089. }
  9090. pthread_exit(NULL);
  9091. }
  9092. //==========================================
  9093. // Handle server response routine
  9094. //==========================================
  9095. void handleAuthorizeResponse(char *payload, int gun_index)
  9096. {
  9097. mtrace();
  9098. char expiryDatestr[30]={0};
  9099. char parentIdTagstr[20]={0};
  9100. char statusstr[20]={0};
  9101. char expiryDatestrtemp[30]={0};
  9102. char parentIdTagstrtemp[20]={0};
  9103. char IdTagstrtemp[20]={0};
  9104. char statusstrtemp[20]={0};
  9105. int expiryDateISNULL=FALSE;
  9106. int parentIdTagISNULL=FALSE;
  9107. char sstr[160]={ 0 };
  9108. char* filename = AuthorizationCache_JSON;
  9109. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9110. int c = 0;
  9111. char *loc;
  9112. int resultRename=0;
  9113. int responseIdTagInfoAsZero= 0;
  9114. char rmFileCmd[50]={0};
  9115. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9116. //***********expiryDate*************/
  9117. loc = strstr(payload, "expiryDate");
  9118. memset(sstr ,0, sizeof(sstr) );
  9119. c = 0;
  9120. if(loc == NULL)
  9121. {
  9122. expiryDateISNULL = TRUE;
  9123. }
  9124. else
  9125. {
  9126. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9127. {
  9128. sstr[c] = loc[3+strlen("expiryDate")+c];
  9129. c++;
  9130. }
  9131. sstr[c] = '\0';
  9132. strcpy(expiryDatestr, sstr);
  9133. }
  9134. //***********parentIdTag*************/
  9135. loc = strstr(payload, "parentIdTag");
  9136. memset(sstr ,0, sizeof(sstr) );
  9137. c = 0;
  9138. if(loc == NULL)
  9139. {
  9140. parentIdTagISNULL = TRUE;
  9141. }
  9142. else
  9143. {
  9144. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9145. {
  9146. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9147. c++;
  9148. }
  9149. sstr[c] = '\0';
  9150. strcpy(parentIdTagstr, sstr);
  9151. }
  9152. //***********status*************/
  9153. loc = strstr(payload, "status");
  9154. memset(sstr ,0, sizeof(sstr) );
  9155. c = 0;
  9156. while (loc[3+strlen("status")+c] != '\"')
  9157. {
  9158. sstr[c] = loc[3+strlen("status")+c];
  9159. c++;
  9160. }
  9161. sstr[c] = '\0';
  9162. strcpy(statusstr, sstr);
  9163. if(expiryDateISNULL == FALSE)
  9164. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9165. if(parentIdTagISNULL == FALSE)
  9166. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9167. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9168. //Update idTag information to authorization cache if supproted
  9169. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9170. {
  9171. if((access(filename,F_OK))!=-1)
  9172. {
  9173. printf("AuthorizationCache exist.\n");
  9174. }
  9175. else
  9176. {
  9177. printf("AuthorizationCache not exist\n");
  9178. FILE *log = fopen(filename, "w+");
  9179. if(log == NULL)
  9180. {
  9181. printf("log is NULL\n");
  9182. goto out;
  9183. }
  9184. else
  9185. {
  9186. fclose(log);
  9187. }
  9188. }
  9189. FILE *infile;
  9190. FILE *outfile;
  9191. // open file for writing
  9192. infile = fopen (filename, "r");
  9193. outfile = fopen (tempfile, "w");
  9194. //*检测到文件结束标识返回1,否则返回0。*/
  9195. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9196. int c;
  9197. c = fgetc(infile);
  9198. //DEBUG_INFO("c:%d\n",c);
  9199. rewind(infile);
  9200. if(c == EOF)
  9201. {
  9202. DEBUG_INFO("Orignal File is NULL\n");
  9203. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9204. {
  9205. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9206. }
  9207. else
  9208. {
  9209. strcpy(expiryDatestrtemp, "");
  9210. }
  9211. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9212. {
  9213. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9214. }
  9215. else
  9216. {
  9217. //write Authorize IdTag
  9218. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9219. }
  9220. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9221. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9222. fclose(infile);
  9223. fclose(outfile);
  9224. sprintf(rmFileCmd,"rm -f %s",filename);
  9225. system(rmFileCmd);
  9226. resultRename = rename(tempfile, filename);
  9227. if(resultRename == 0)
  9228. {
  9229. printf("File renamed successfully");
  9230. }
  9231. else
  9232. {
  9233. printf("Error: unable to rename the file");
  9234. }
  9235. }
  9236. else
  9237. {
  9238. char buf[160]={0};
  9239. while (fgets(buf, sizeof(buf), infile) != NULL)
  9240. {
  9241. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9242. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9243. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9244. memset(statusstr, 0, sizeof(statusstrtemp));
  9245. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9246. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9247. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9248. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9249. //------------------IdTag-----------------------
  9250. loc = strstr(buf, "idTag");
  9251. memset(sstr ,0, sizeof(sstr) );
  9252. c = 0;
  9253. while (loc[3+strlen("idTag")+c] != '\"')
  9254. {
  9255. sstr[c] = loc[3+strlen("idTag")+c];
  9256. c++;
  9257. }
  9258. sstr[c] = '\0';
  9259. strcpy(IdTagstrtemp,sstr);
  9260. //*********************expiryDate***************/
  9261. loc = strstr(buf, "expiryDate");
  9262. memset(sstr ,0, sizeof(sstr) );
  9263. c = 0;
  9264. while (loc[3+strlen("expiryDate")+c] != '\"')
  9265. {
  9266. sstr[c] = loc[3+strlen("expiryDate")+c];
  9267. c++;
  9268. }
  9269. sstr[c] = '\0';
  9270. strcpy(expiryDatestr,sstr);
  9271. //*********************parentIdTag***************/
  9272. loc = strstr(buf, "parentIdTag");
  9273. memset(sstr ,0, sizeof(sstr) );
  9274. c = 0;
  9275. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9276. {
  9277. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9278. c++;
  9279. }
  9280. sstr[c] = '\0';
  9281. strcpy(parentIdTagstr,sstr);
  9282. //*********************status***************/
  9283. loc = strstr(buf, "status");
  9284. memset(sstr ,0, sizeof(sstr) );
  9285. c = 0;
  9286. while (loc[3+strlen("status")+c] != '\"')
  9287. {
  9288. sstr[c] = loc[3+strlen("status")+c];
  9289. c++;
  9290. }
  9291. sstr[c] = '\0';
  9292. strcpy(statusstr,sstr);
  9293. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9294. {
  9295. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9296. responseIdTagInfoAsZero = 1;
  9297. }
  9298. else
  9299. {
  9300. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9301. }
  9302. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9303. {
  9304. //modify item
  9305. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9306. {
  9307. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9308. }
  9309. else
  9310. {
  9311. strcpy(expiryDatestrtemp, "");
  9312. }
  9313. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9314. {
  9315. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9316. }
  9317. else
  9318. {
  9319. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9320. }
  9321. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9322. }
  9323. else
  9324. {
  9325. //wrie original item
  9326. strcpy(expiryDatestrtemp, expiryDatestr);
  9327. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9328. strcpy(statusstrtemp, statusstr);
  9329. }
  9330. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9331. }
  9332. fclose(infile);
  9333. fclose(outfile);
  9334. sprintf(rmFileCmd,"rm -f %s",filename);
  9335. system(rmFileCmd);
  9336. resultRename = rename(tempfile, filename);
  9337. if(resultRename == 0)
  9338. {
  9339. DEBUG_INFO("File renamed successfully");
  9340. }
  9341. else
  9342. {
  9343. DEBUG_INFO("Error: unable to rename the file");
  9344. }
  9345. }
  9346. }
  9347. out:
  9348. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9349. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9350. authorizeRetryTimes = 0;
  9351. }
  9352. void handleBootNotificationResponse(char *payload, int gun_index)
  9353. {
  9354. mtrace();
  9355. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9356. char statusStr[12]={0};
  9357. char currentTimeStr[30]={0};
  9358. char *loc;
  9359. int intervalInt = 0;
  9360. int c = 0;
  9361. //double diff_t;
  9362. struct tm tp;
  9363. char buf[28]={0};
  9364. char timebuf[50]={0};
  9365. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9366. //*** interval ****/
  9367. c = 0;
  9368. loc = strstr(payload, "interval");
  9369. //printf("loc=%s\n",loc);
  9370. memset(sstr ,0, sizeof(sstr) );
  9371. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9372. {
  9373. sstr[c] = loc[strlen("interval")+2+c];
  9374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9375. c++;
  9376. }
  9377. sstr[c] = '\0';
  9378. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9379. intervalInt = atoi(sstr);
  9380. //***status ****/
  9381. loc = strstr(payload, "status");
  9382. memset(sstr ,0, sizeof(sstr) );
  9383. c = 0;
  9384. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9385. {
  9386. sstr[c] = loc[3+strlen("status")+c];
  9387. c++;
  9388. }
  9389. sstr[c] = '\0';
  9390. strcpy(statusStr, sstr);
  9391. //***currentTime ****/
  9392. loc = strstr(payload, "currentTime");
  9393. //printf("loc=%s\n",loc);
  9394. memset(sstr ,0, sizeof(sstr) );
  9395. c = 0;
  9396. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9397. {
  9398. sstr[c] = loc[3+strlen("currentTime")+c];
  9399. c++;
  9400. }
  9401. sstr[c] = '\0';
  9402. strcpy(currentTimeStr, sstr);
  9403. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9404. HeartBeatWaitTime = BootNotificationInterval;
  9405. clientTime.Heartbeat=time((time_t*)NULL);
  9406. //write back to ShmOCPP16Data->BootNotification
  9407. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9408. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9409. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9410. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9411. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9412. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9413. {
  9414. server_sign = TRUE;
  9415. server_pending =FALSE;
  9416. }
  9417. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9418. {
  9419. server_pending = TRUE;
  9420. }
  9421. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9422. tp.tm_isdst = -1;
  9423. //time_t utc = mktime(&tp);
  9424. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9425. memset(timebuf, 0, sizeof timebuf);
  9426. sprintf(timebuf,"date -s '%s'",buf);
  9427. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9428. system(timebuf);
  9429. //==============================================
  9430. // RTC sync
  9431. //==============================================
  9432. system("/sbin/hwclock -w --systohc");
  9433. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9434. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9435. }
  9436. void handleDataTransferResponse(char *payload, int gun_index)
  9437. {
  9438. char sstr[160]={0};//sstr[200]={ 0 };
  9439. int c = 0;
  9440. char *loc;
  9441. DEBUG_INFO("handleDataTransferResponse ...\n");
  9442. loc = strstr(payload, "status");
  9443. printf("loc=%s\n",loc);
  9444. c = 0;
  9445. while (loc[3+strlen("status")+c] != '\"')
  9446. {
  9447. sstr[c] = loc[3+strlen("status")+c];
  9448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9449. c++;
  9450. }
  9451. sstr[c] = '\0';
  9452. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9453. }
  9454. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9455. {
  9456. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9457. //struct json_object *obj;
  9458. // obj = json_tokener_parse(payload);
  9459. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9460. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9461. //No fields are defined.
  9462. }
  9463. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9464. {
  9465. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9466. //struct json_object *obj;
  9467. // obj = json_tokener_parse(payload);
  9468. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9470. //No fields are defined.
  9471. }
  9472. void handleHeartbeatResponse(char *payload, int gun_index)
  9473. {
  9474. mtrace();
  9475. //double diff_t;
  9476. struct tm tp;
  9477. char buf[28]={0};
  9478. char timebuf[50]={0};
  9479. char sstr[30]={ 0 };
  9480. int c = 0;
  9481. char *loc;
  9482. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9483. c = 0;
  9484. loc = strstr(payload, "currentTime");
  9485. memset(sstr ,0, sizeof(sstr) );
  9486. while (loc[3+strlen("currentTime")+c] != '\"')
  9487. {
  9488. sstr[c] = loc[3+strlen("currentTime")+c];
  9489. c++;
  9490. }
  9491. sstr[c] = '\0';
  9492. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9493. // #ifdef SystemLogMessage
  9494. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9495. // #endif
  9496. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9497. tp.tm_isdst = -1;
  9498. //time_t utc = mktime(&tp);
  9499. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9500. memset(timebuf, 0, sizeof timebuf);
  9501. sprintf(timebuf,"date -s '%s'",buf);
  9502. system(timebuf);
  9503. //==============================================
  9504. // RTC sync
  9505. //==============================================
  9506. system("/sbin/hwclock -w --systohc");
  9507. if(FirstHeartBeat == 0)
  9508. {
  9509. FirstHeartBeat = 1;
  9510. }
  9511. HeartBeatWithNOResponse = 0;
  9512. //--------Print Out HeartBeat log
  9513. {
  9514. double diff_t;
  9515. struct tm tp,tp1;
  9516. // BootNotification Receive Time
  9517. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9518. tp.tm_isdst = -1;
  9519. time_t BootNotificationReceiveTime = mktime(&tp);
  9520. //HeartBeat Receive Time
  9521. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9522. tp1.tm_isdst = -1;
  9523. time_t HeartBeatReceiveTime = mktime(&tp1);
  9524. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9525. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9526. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9527. {
  9528. HeartBeatCountPerHour = (int)diff_t / 3600;
  9529. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9530. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9531. }
  9532. }
  9533. }
  9534. void handleMeterValuesResponse(char *payload, int gun_index)
  9535. {
  9536. mtrace();
  9537. //struct json_object *obj;
  9538. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9539. //No fields are defined.
  9540. }
  9541. void handleStartTransactionResponse(char *payload, int gun_index)
  9542. {
  9543. mtrace();
  9544. char sstr[28]={ 0 };
  9545. int c = 0;
  9546. char *loc;
  9547. int transactionIdInt = 0;
  9548. FILE *outfile;
  9549. char data[100]={0};
  9550. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9551. DEBUG_INFO("handleStartTransactionResponse\n");
  9552. //****************expiryDate********************/
  9553. loc = strstr(payload, "expiryDate");
  9554. if(loc == NULL)
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9557. }
  9558. else
  9559. {
  9560. c = 0;
  9561. memset(sstr ,0, sizeof(sstr) );
  9562. while (loc[3+strlen("expiryDate")+c] != '\"')
  9563. {
  9564. sstr[c] = loc[3+strlen("expiryDate")+c];
  9565. c++;
  9566. }
  9567. sstr[c] = '\0';
  9568. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9569. }
  9570. //****************parentIdTag********************/
  9571. loc = strstr(payload, "parentIdTag");
  9572. if(loc == NULL)
  9573. {
  9574. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9575. }
  9576. else
  9577. {
  9578. c = 0;
  9579. memset(sstr ,0, sizeof(sstr) );
  9580. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9581. {
  9582. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9583. c++;
  9584. }
  9585. sstr[c] = '\0';
  9586. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9587. }
  9588. //****************status********************/
  9589. loc = strstr(payload, "status");
  9590. if(loc == NULL)
  9591. {
  9592. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9593. }
  9594. else
  9595. {
  9596. c = 0;
  9597. memset(sstr ,0, sizeof(sstr) );
  9598. while (loc[3+strlen("status")+c] != '\"')
  9599. {
  9600. sstr[c] = loc[3+strlen("status")+c];
  9601. c++;
  9602. }
  9603. sstr[c] = '\0';
  9604. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9605. }
  9606. //****************transactionId********************/
  9607. c=0;
  9608. loc = strstr(payload, "transactionId");
  9609. memset(sstr ,0, sizeof(sstr) );
  9610. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9611. {
  9612. sstr[c] = loc[strlen("transactionId")+2+c];
  9613. c++;
  9614. }
  9615. sstr[c] = '\0';
  9616. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9617. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9618. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9619. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9620. //-----------Start : write to the Queue TransactionId file -----------------//
  9621. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9622. {
  9623. //DEBUG_INFO("QueueTransactionId exist.\n");
  9624. }
  9625. else
  9626. {
  9627. //DEBUG_INFO("QueueTransactionId not exist\n");
  9628. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9629. if(log == NULL)
  9630. {
  9631. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9632. return ;
  9633. }
  9634. else
  9635. {
  9636. fclose(log);
  9637. }
  9638. }
  9639. // open file for writing
  9640. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9641. //DEBUG_INFO("data=%s\n",data);
  9642. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9643. fputs(data, outfile);
  9644. //fputs("\n", outfile);
  9645. fclose (outfile);
  9646. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9647. TransactionId[gun_index] = transactionIdInt;
  9648. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9649. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9650. #ifdef SystemLogMessage
  9651. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9652. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9653. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9654. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9655. #endif
  9656. }
  9657. void handleStatusNotificationResponse(char *payload, int gun_index)
  9658. {
  9659. mtrace();
  9660. printf("handleStatusNotificationResponse\n");
  9661. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9662. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9663. }
  9664. void handleStopTransactionnResponse(char *payload, int gun_index)
  9665. {
  9666. mtrace();
  9667. char sstr[30]={ 0 };
  9668. int c = 0;
  9669. char *loc;
  9670. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9671. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9672. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9673. loc = strstr(payload, "idTagInfo");
  9674. //***********************idTagInfo************************/
  9675. if(loc != NULL)
  9676. {
  9677. //***********************expiryDate************************/
  9678. loc = strstr(payload, "expiryDate");
  9679. if(loc != NULL)
  9680. {
  9681. memset(sstr ,0, sizeof(sstr) );
  9682. c = 0;
  9683. while (loc[3+strlen("expiryDate")+c] != '\"')
  9684. {
  9685. sstr[c] = loc[3+strlen("expiryDate")+c];
  9686. c++;
  9687. }
  9688. sstr[c] = '\0';
  9689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9690. }
  9691. //***********************parentIdTag************************/
  9692. loc = strstr(payload, "parentIdTag");
  9693. if(loc != NULL)
  9694. {
  9695. memset(sstr ,0, sizeof(sstr) );
  9696. c = 0;
  9697. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9698. {
  9699. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9700. c++;
  9701. }
  9702. sstr[c] = '\0';
  9703. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9704. }
  9705. //***********************status************************/
  9706. loc = strstr(payload, "status");
  9707. memset(sstr ,0, sizeof(sstr) );
  9708. c = 0;
  9709. while (loc[3+strlen("status")+c] != '\"')
  9710. {
  9711. sstr[c] = loc[3+strlen("status")+c];
  9712. c++;
  9713. }
  9714. sstr[c] = '\0';
  9715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9716. }
  9717. #ifdef SystemLogMessage
  9718. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9719. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9720. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9721. #endif
  9722. }
  9723. //==========================================
  9724. // Handle Error routine
  9725. //==========================================
  9726. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9727. {
  9728. mtrace();
  9729. #ifdef SystemLogMessage
  9730. DEBUG_INFO("errorCode: %s\n", errorCode);
  9731. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9732. DEBUG_INFO("errorDetails: %s\n", payload);
  9733. #endif
  9734. }
  9735. //===============================================
  9736. // Common routine
  9737. //===============================================
  9738. int initialConfigurationTable(void)
  9739. {
  9740. //clock_t start_t, end_t, total_t;
  9741. FILE *fp;
  9742. FILE *outfile;
  9743. char str[200]={0};
  9744. char sstr[100]={0};
  9745. int c = 0;
  9746. char *loc;
  9747. printf("initialConfigurationTable \n");
  9748. //start_t = clock();
  9749. //printf("Starting of the program, start_t = %ld\n", start_t);
  9750. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9751. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9752. {
  9753. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9754. if(outfile == NULL) {
  9755. DEBUG_INFO("Error opening file");
  9756. return FALSE;
  9757. }
  9758. /*Core Profile*/
  9759. //AllowOfflineTxForUnknownId
  9760. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 0;
  9761. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", "FALSE");
  9765. //AuthorizationCacheEnabled
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9770. //AuthorizeRemoteTxRequests
  9771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9775. //BlinkRepeat
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9780. //ClockAlignedDataInterval
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9785. //ConnectionTimeOut
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9790. //GetConfigurationMaxKeys
  9791. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9795. // HeartbeatInterval
  9796. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9800. // LightIntensity
  9801. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9805. // LocalAuthorizeOffline
  9806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9810. // LocalPreAuthorize
  9811. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9815. // MaxEnergyOnInvalidId
  9816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9819. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9821. // MeterValuesAlignedData
  9822. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9826. // MeterValuesAlignedDataMaxLength
  9827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9831. // MeterValuesSampledData
  9832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9836. // MeterValuesSampledDataMaxLength
  9837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9841. // MeterValueSampleInterval
  9842. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9846. // MinimumStatusDuration
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9850. server_cycle_Status = 120; //StatusNotification cycle
  9851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9852. // NumberOfConnectors
  9853. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9856. {
  9857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9858. }
  9859. else
  9860. {
  9861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9862. }
  9863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9864. // ResetRetries
  9865. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9869. // ConnectorPhaseRotation
  9870. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9874. // ConnectorPhaseRotationMaxLength
  9875. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9879. // StopTransactionOnEVSideDisconnect
  9880. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9884. // StopTransactionOnInvalidId
  9885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9889. // StopTxnAlignedData
  9890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  9894. // StopTxnAlignedDataMaxLength
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9899. // StopTxnSampledData
  9900. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9904. // StopTxnSampledDataMaxLength
  9905. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9908. {
  9909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9910. }
  9911. else
  9912. {
  9913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9914. }
  9915. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9917. // SupportedFeatureProfiles
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9922. // SupportedFeatureProfilesMaxLength
  9923. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9927. // TransactionMessageAttempts
  9928. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9931. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9933. // TransactionMessageRetryInterval
  9934. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9937. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9939. // UnlockConnectorOnEVSideDisconnect
  9940. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9944. // WebSocketPingInterval
  9945. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9949. //* Local Auth List Management Profile*/
  9950. #if 0
  9951. //For OCTT Test Case
  9952. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9955. #endif
  9956. #if 1
  9957. //LocalAuthListEnabled
  9958. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9962. #endif
  9963. //LocalAuthListMaxLength
  9964. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9968. //SendLocalListMaxLength
  9969. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9973. //ReserveConnectorZeroSupported
  9974. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9978. //* Smart Charging Profile */
  9979. //ChargeProfileMaxStackLevel
  9980. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9984. // ChargingScheduleAllowedChargingRateUnit
  9985. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9989. // ChargingScheduleMaxPeriods
  9990. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9994. // ConnectorSwitch3to1PhaseSupported
  9995. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9999. // MaxChargingProfilesInstalled
  10000. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  10004. fclose(outfile);
  10005. }
  10006. else
  10007. {
  10008. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10009. char keystr[60]={0};
  10010. char readonlystr[10]={0};
  10011. char valuestr[100]={0};
  10012. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10013. if(fp == NULL) {
  10014. DEBUG_INFO("Error opening file");
  10015. return FALSE;
  10016. }
  10017. while( fgets (str, sizeof(str), fp)!=NULL )
  10018. {
  10019. //DEBUG_INFO("Get Configuration \n");
  10020. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10021. //*************************key*********************************/
  10022. loc = strstr(str, "key");
  10023. c = 0;
  10024. memset(sstr ,0, sizeof(sstr) );
  10025. while (loc[strlen("key")+3+c] != '\"')
  10026. {
  10027. sstr[c] = loc[strlen("key")+3+c];
  10028. c++;
  10029. }
  10030. sstr[c] = '\0';
  10031. strcpy(keystr,sstr);
  10032. //*************************readonly*********************************/
  10033. loc = strstr(str, "readonly");
  10034. c = 0;
  10035. memset(sstr ,0, sizeof(sstr) );
  10036. while (loc[strlen("readonly")+2+c] != ',')
  10037. {
  10038. sstr[c] = loc[strlen("readonly")+2+c];
  10039. c++;
  10040. }
  10041. sstr[c] = '\0';
  10042. strcpy(readonlystr,sstr);
  10043. //*************************value*********************************/
  10044. loc = strstr(str, "value");
  10045. c = 0;
  10046. memset(sstr ,0, sizeof(sstr) );
  10047. while (loc[strlen("value")+3+c] != '\"')
  10048. {
  10049. sstr[c] = loc[strlen("value")+3+c];
  10050. c++;
  10051. }
  10052. sstr[c] = '\0';
  10053. strcpy(valuestr,sstr);
  10054. // DEBUG_INFO("keystr=%s\n",keystr);
  10055. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10056. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10057. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10058. {
  10059. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10062. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10063. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10064. }
  10065. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10066. {
  10067. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10070. }
  10071. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10072. {
  10073. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10075. }
  10076. if(strcmp(keystr, "BlinkRepeat") == 0)
  10077. {
  10078. //Charger.BlinkRepeat = Integer.parseInt(value);
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10081. }
  10082. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10083. {
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10086. }
  10087. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10088. {
  10089. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10091. }
  10092. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10093. {
  10094. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10096. }
  10097. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10098. {
  10099. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10101. HeartBeatWaitTime = atoi(valuestr);
  10102. }
  10103. if(strcmp(keystr, "LightIntensity") == 0)
  10104. {
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10107. }
  10108. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10109. {
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10112. }
  10113. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10114. {
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10117. }
  10118. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10119. {
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10122. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10123. }
  10124. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10125. {
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10128. }
  10129. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10130. {
  10131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10133. }
  10134. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10135. {
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10138. }
  10139. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10140. {
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10143. }
  10144. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10145. {
  10146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10148. }
  10149. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10150. {
  10151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10153. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10154. }
  10155. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10156. {
  10157. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10159. }
  10160. if(strcmp(keystr, "ResetRetries") == 0)
  10161. {
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10164. }
  10165. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10166. {
  10167. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10169. }
  10170. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10171. {
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10174. }
  10175. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10176. {
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10179. }
  10180. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10181. {
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10184. }
  10185. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10186. {
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10189. }
  10190. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10191. {
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10194. }
  10195. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10201. {
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10204. }
  10205. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10206. {
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10209. }
  10210. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10211. {
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10214. }
  10215. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10216. {
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10219. TransactionMessageAttemptsValue = atoi(valuestr);
  10220. }
  10221. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10222. {
  10223. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10225. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10226. }
  10227. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10228. {
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10231. }
  10232. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10233. {
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10236. }
  10237. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10238. {
  10239. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10241. }
  10242. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10243. {
  10244. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10246. }
  10247. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10248. {
  10249. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10251. }
  10252. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10253. {
  10254. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10256. }
  10257. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10258. {
  10259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10261. }
  10262. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10263. {
  10264. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10266. }
  10267. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10268. {
  10269. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10271. }
  10272. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10273. {
  10274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10276. }
  10277. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10278. {
  10279. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10281. }
  10282. }
  10283. fclose(fp);
  10284. }
  10285. //end_t = clock();
  10286. //printf("End of the big loop, end_t = %ld\n", end_t);
  10287. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10288. //printf("Total time taken by CPU: %f\n", total_t );
  10289. return 0;
  10290. }
  10291. void StoreConfigurationTable(void)
  10292. {
  10293. FILE *outfile;
  10294. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10295. if(outfile == NULL)
  10296. {
  10297. DEBUG_INFO("Error opening file");
  10298. return ;
  10299. }
  10300. /*Core Profile*/
  10301. //AllowOfflineTxForUnknownId
  10302. /*
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10304. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10307. */
  10308. //DEBUG_INFO("data=%s\n",data);
  10309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10310. //AuthorizationCacheEnabled
  10311. /*
  10312. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10315. */
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10317. //AuthorizeRemoteTxRequests
  10318. /*
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10322. */
  10323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10324. //BlinkRepeat
  10325. /*
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10329. */
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10331. //ClockAlignedDataInterval
  10332. /*
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10336. */
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10338. //ConnectionTimeOut
  10339. /*
  10340. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10343. */
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10345. //GetConfigurationMaxKeys
  10346. /*
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10350. */
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10352. // HeartbeatInterval
  10353. /*
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10357. */
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10359. // LightIntensity
  10360. /*
  10361. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10364. */
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10366. // LocalAuthorizeOffline
  10367. /*
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10371. */
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10373. // LocalPreAuthorize
  10374. /*
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10378. */
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10380. // MaxEnergyOnInvalidId
  10381. /*
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10385. */
  10386. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10388. // MeterValuesAlignedData
  10389. /*
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10393. */
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10395. // MeterValuesAlignedDataMaxLength
  10396. /*
  10397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10400. */
  10401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10402. // MeterValuesSampledData
  10403. /*
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10407. */
  10408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10409. // MeterValuesSampledDataMaxLength
  10410. /*
  10411. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10414. */
  10415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10416. // MeterValueSampleInterval
  10417. /*
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10421. */
  10422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10423. // MinimumStatusDuration
  10424. /*
  10425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10428. */
  10429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10430. // NumberOfConnectors
  10431. /*
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10435. {
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10437. }
  10438. else
  10439. {
  10440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10441. }
  10442. */
  10443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10444. // ResetRetries
  10445. /*
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10449. */
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10451. // ConnectorPhaseRotation
  10452. /*
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10456. */
  10457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10458. // ConnectorPhaseRotationMaxLength
  10459. /*
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10463. */
  10464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10465. // StopTransactionOnEVSideDisconnect
  10466. /*
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10470. */
  10471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10472. // StopTransactionOnInvalidId
  10473. /*
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10477. */
  10478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10479. // StopTxnAlignedData
  10480. /*
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10484. */
  10485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10486. // StopTxnAlignedDataMaxLength
  10487. /*
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10491. */
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10493. // StopTxnSampledData
  10494. /*
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10498. */
  10499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10500. // StopTxnSampledDataMaxLength
  10501. /*
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10505. */
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10507. // SupportedFeatureProfiles
  10508. /*
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10512. */
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10514. // SupportedFeatureProfilesMaxLength
  10515. /*
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10519. */
  10520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10521. // TransactionMessageAttempts
  10522. /*
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10526. */
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10528. // TransactionMessageRetryInterval
  10529. /*
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10533. */
  10534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10535. // UnlockConnectorOnEVSideDisconnect
  10536. /*
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10540. */
  10541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10542. // WebSocketPingInterval
  10543. /*
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10547. */
  10548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10549. //* Local Auth List Management Profile*/
  10550. //LocalAuthListEnabled
  10551. /*
  10552. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10555. */
  10556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10557. //LocalAuthListMaxLength
  10558. /*
  10559. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10562. */
  10563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10564. //SendLocalListMaxLength
  10565. /*
  10566. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10569. */
  10570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10571. //ReserveConnectorZeroSupported
  10572. /*
  10573. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10576. */
  10577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10578. //* Smart Charging Profile */
  10579. //ChargeProfileMaxStackLevel
  10580. /*
  10581. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10584. */
  10585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10586. // ChargingScheduleAllowedChargingRateUnit
  10587. /*
  10588. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10591. */
  10592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10593. // ChargingScheduleMaxPeriods
  10594. /*
  10595. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10598. */
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10600. // ConnectorSwitch3to1PhaseSupported
  10601. /*
  10602. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10605. */
  10606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10607. // MaxChargingProfilesInstalled
  10608. /*
  10609. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10612. */
  10613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10614. fclose(outfile);
  10615. }
  10616. void getKeyValue(char *keyReq)
  10617. {
  10618. int isEmpty = FALSE;
  10619. int isKnowKey = FALSE;
  10620. //int unKnowIndex = 0;
  10621. DEBUG_INFO("getKeyValue \n");
  10622. DEBUG_INFO("keyReq=%s \n",keyReq);
  10623. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10624. isEmpty = TRUE;
  10625. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10626. {
  10627. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10630. {
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10632. }
  10633. else
  10634. {
  10635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10636. }
  10637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10638. isKnowKey = TRUE;
  10639. }
  10640. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10641. {
  10642. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10645. {
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10647. }
  10648. else
  10649. {
  10650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10651. }
  10652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10653. isKnowKey = TRUE;
  10654. }
  10655. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10656. {
  10657. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10660. {
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10662. }
  10663. else
  10664. {
  10665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10666. }
  10667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10668. isKnowKey = TRUE;
  10669. }
  10670. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10671. {
  10672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10675. {
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10677. }
  10678. else
  10679. {
  10680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10681. }
  10682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10683. isKnowKey = TRUE;
  10684. }
  10685. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10686. {
  10687. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10690. {
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10692. }
  10693. else
  10694. {
  10695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10696. }
  10697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10698. isKnowKey = TRUE;
  10699. }
  10700. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10701. {
  10702. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10705. {
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10707. }
  10708. else
  10709. {
  10710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10711. }
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10713. isKnowKey = TRUE;
  10714. }
  10715. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10716. {
  10717. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10720. {
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10722. }
  10723. else
  10724. {
  10725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10726. }
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10728. isKnowKey = TRUE;
  10729. }
  10730. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10731. {
  10732. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10735. {
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10737. }
  10738. else
  10739. {
  10740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10741. }
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10743. isKnowKey = TRUE;
  10744. }
  10745. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10746. {
  10747. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10750. {
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10752. }
  10753. else
  10754. {
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10756. }
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10758. isKnowKey = TRUE;
  10759. }
  10760. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10761. {
  10762. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10765. {
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10767. }
  10768. else
  10769. {
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10771. }
  10772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10773. isKnowKey = TRUE;
  10774. }
  10775. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10776. {
  10777. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10780. {
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10782. }
  10783. else
  10784. {
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10786. }
  10787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10788. isKnowKey = TRUE;
  10789. }
  10790. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10791. {
  10792. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10795. {
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10797. }
  10798. else
  10799. {
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10801. }
  10802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10803. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10804. isKnowKey = TRUE;
  10805. }
  10806. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10807. {
  10808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10811. {
  10812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10813. }
  10814. else
  10815. {
  10816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10817. }
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10819. isKnowKey = TRUE;
  10820. }
  10821. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10822. {
  10823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10826. {
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10828. }
  10829. else
  10830. {
  10831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10832. }
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10834. isKnowKey = TRUE;
  10835. }
  10836. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10837. {
  10838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10841. {
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10843. }
  10844. else
  10845. {
  10846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10847. }
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10849. isKnowKey = TRUE;
  10850. }
  10851. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10852. {
  10853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10856. {
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10858. }
  10859. else
  10860. {
  10861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10862. }
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10864. isKnowKey = TRUE;
  10865. }
  10866. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10867. {
  10868. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10871. {
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10873. }
  10874. else
  10875. {
  10876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10877. }
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10879. isKnowKey = TRUE;
  10880. }
  10881. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10882. {
  10883. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10886. {
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10888. }
  10889. else
  10890. {
  10891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10892. }
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10894. isKnowKey = TRUE;
  10895. }
  10896. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10897. {
  10898. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10901. {
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10903. }
  10904. else
  10905. {
  10906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10907. }
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10909. isKnowKey = TRUE;
  10910. }
  10911. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10912. {
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10916. {
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10918. }
  10919. else
  10920. {
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10922. }
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10924. isKnowKey = TRUE;
  10925. }
  10926. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10927. {
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10931. {
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10933. }
  10934. else
  10935. {
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10937. }
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10939. isKnowKey = TRUE;
  10940. }
  10941. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10946. {
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10948. }
  10949. else
  10950. {
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10952. }
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10954. isKnowKey = TRUE;
  10955. }
  10956. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10963. }
  10964. else
  10965. {
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10967. }
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10969. isKnowKey = TRUE;
  10970. }
  10971. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10976. {
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10978. }
  10979. else
  10980. {
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10982. }
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10984. isKnowKey = TRUE;
  10985. }
  10986. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10991. {
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10993. }
  10994. else
  10995. {
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10997. }
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10999. isKnowKey = TRUE;
  11000. }
  11001. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11006. {
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11008. }
  11009. else
  11010. {
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11012. }
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11014. isKnowKey = TRUE;
  11015. }
  11016. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11021. {
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11023. }
  11024. else
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11027. }
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11029. isKnowKey = TRUE;
  11030. }
  11031. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11036. {
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11038. }
  11039. else
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11042. }
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11044. isKnowKey = TRUE;
  11045. }
  11046. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11051. {
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11053. }
  11054. else
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11057. }
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11059. isKnowKey = TRUE;
  11060. }
  11061. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11066. {
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11068. }
  11069. else
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11072. }
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11074. isKnowKey = TRUE;
  11075. }
  11076. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11083. }
  11084. else
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11087. }
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11089. isKnowKey = TRUE;
  11090. }
  11091. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11098. }
  11099. else
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11102. }
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11104. isKnowKey = TRUE;
  11105. }
  11106. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11113. }
  11114. else
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11117. }
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11119. isKnowKey = TRUE;
  11120. }
  11121. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11128. }
  11129. else
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11132. }
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11134. isKnowKey = TRUE;
  11135. }
  11136. #if 0
  11137. //For OCTT Test Case
  11138. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11142. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11145. }
  11146. else
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11149. }
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11151. isKnowKey = TRUE;
  11152. }
  11153. #endif
  11154. #if 1
  11155. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11159. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11162. }
  11163. else
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11166. }
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11168. isKnowKey = TRUE;
  11169. }
  11170. #endif
  11171. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11175. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11178. }
  11179. else
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11182. }
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11184. isKnowKey = TRUE;
  11185. }
  11186. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11190. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11193. }
  11194. else
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11197. }
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11199. isKnowKey = TRUE;
  11200. }
  11201. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11205. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11208. }
  11209. else
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11212. }
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11214. isKnowKey = TRUE;
  11215. }
  11216. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11220. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11223. }
  11224. else
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11227. }
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11229. isKnowKey = TRUE;
  11230. }
  11231. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11235. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11238. }
  11239. else
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11242. }
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11244. isKnowKey = TRUE;
  11245. }
  11246. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11250. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11253. }
  11254. else
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11257. }
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11259. isKnowKey = TRUE;
  11260. }
  11261. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11265. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11268. }
  11269. else
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11272. }
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11274. isKnowKey = TRUE;
  11275. }
  11276. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11280. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11283. }
  11284. else
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11287. }
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11289. isKnowKey = TRUE;
  11290. }
  11291. //=========================================================
  11292. if(!isEmpty && !isKnowKey)
  11293. {
  11294. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11295. strcpy(unknownkey[UnknownKeynum], keyReq);
  11296. UnknownKeynum = UnknownKeynum + 1;
  11297. }
  11298. }
  11299. void processUnkownKey(void)
  11300. {
  11301. DEBUG_INFO("processUnkownKey\n");
  11302. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11303. for(int index=0; index < UnknownKeynum; index++)
  11304. {
  11305. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11306. {
  11307. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11308. }
  11309. }
  11310. }
  11311. int setKeyValue(char *key, char *value)
  11312. {
  11313. int isSuccess = NotSupported;
  11314. int check_ascii=0;
  11315. char str[10]={0};
  11316. #ifdef Debug
  11317. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11318. #endif
  11319. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11320. {
  11321. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11323. {
  11324. strcpy(str, (const char*)value);
  11325. for(int i = 0; str[i]; i++){
  11326. str[i] = tolower(str[i]);
  11327. }
  11328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11329. isSuccess = ConfigurationStatus_Accepted;
  11330. }
  11331. else
  11332. {
  11333. isSuccess = ConfigurationStatus_Rejected;
  11334. }
  11335. }
  11336. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11337. {
  11338. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11340. {
  11341. strcpy(str, (const char*)value);
  11342. for(int i = 0; str[i]; i++){
  11343. str[i] = tolower(str[i]);
  11344. }
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11346. isSuccess = ConfigurationStatus_Accepted;
  11347. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11348. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11349. }
  11350. else
  11351. {
  11352. isSuccess = ConfigurationStatus_Rejected;
  11353. }
  11354. }
  11355. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11356. {
  11357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11358. {
  11359. strcpy(str, (const char*)value);
  11360. for(int i = 0; str[i]; i++)
  11361. {
  11362. str[i] = tolower(str[i]);
  11363. }
  11364. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11366. isSuccess = ConfigurationStatus_Accepted;
  11367. }
  11368. else
  11369. {
  11370. isSuccess = ConfigurationStatus_Rejected;
  11371. }
  11372. }
  11373. if(strcmp(key, "BlinkRepeat") == 0)
  11374. {
  11375. //Charger.BlinkRepeat = Integer.parseInt(value);
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11377. {
  11378. check_ascii = value[0];
  11379. if( (check_ascii < 48) || (check_ascii > 57) )
  11380. {
  11381. isSuccess = ConfigurationStatus_Rejected;
  11382. }
  11383. else
  11384. {
  11385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11386. isSuccess = ConfigurationStatus_Accepted;
  11387. }
  11388. }
  11389. else
  11390. {
  11391. isSuccess = ConfigurationStatus_Rejected;
  11392. }
  11393. }
  11394. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11395. {
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11397. {
  11398. check_ascii = value[0];
  11399. if( (check_ascii < 48) || (check_ascii > 57) )
  11400. {
  11401. isSuccess = ConfigurationStatus_Rejected;
  11402. }
  11403. else
  11404. {
  11405. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11407. isSuccess = ConfigurationStatus_Accepted;
  11408. }
  11409. }
  11410. else
  11411. {
  11412. isSuccess = ConfigurationStatus_Rejected;
  11413. }
  11414. }
  11415. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11416. {
  11417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11418. {
  11419. check_ascii = value[0];
  11420. if( (check_ascii < 48) || (check_ascii > 57) )
  11421. {
  11422. isSuccess = ConfigurationStatus_Rejected;
  11423. }
  11424. else
  11425. {
  11426. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11428. isSuccess = ConfigurationStatus_Accepted;
  11429. }
  11430. }
  11431. else
  11432. {
  11433. isSuccess = ConfigurationStatus_Rejected;
  11434. }
  11435. }
  11436. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11437. {
  11438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11439. {
  11440. check_ascii = value[0];
  11441. if( (check_ascii < 48) || (check_ascii > 57) )
  11442. {
  11443. isSuccess = ConfigurationStatus_Rejected;
  11444. }
  11445. else
  11446. {
  11447. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11449. isSuccess = ConfigurationStatus_Accepted;
  11450. }
  11451. }
  11452. else
  11453. {
  11454. isSuccess = ConfigurationStatus_Rejected;
  11455. }
  11456. }
  11457. if(strcmp(key, "HeartbeatInterval") == 0)
  11458. {
  11459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11460. {
  11461. check_ascii = value[0];
  11462. if( (check_ascii < 48) || (check_ascii > 57) )
  11463. {
  11464. isSuccess = ConfigurationStatus_Rejected;
  11465. }
  11466. else
  11467. {
  11468. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11470. HeartBeatWaitTime = atoi(value);
  11471. isSuccess = ConfigurationStatus_Accepted;
  11472. }
  11473. }
  11474. else
  11475. {
  11476. isSuccess = ConfigurationStatus_Rejected;
  11477. }
  11478. }
  11479. if(strcmp(key, "LightIntensity") == 0)
  11480. {
  11481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11482. {
  11483. check_ascii = value[0];
  11484. if( (check_ascii < 48) || (check_ascii > 57) )
  11485. {
  11486. isSuccess = ConfigurationStatus_Rejected;
  11487. }
  11488. else
  11489. {
  11490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11491. isSuccess = ConfigurationStatus_Accepted;
  11492. }
  11493. }
  11494. else
  11495. {
  11496. isSuccess = ConfigurationStatus_Rejected;
  11497. }
  11498. }
  11499. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11500. {
  11501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11502. {
  11503. strcpy(str, (const char*)value);
  11504. for(int i = 0; str[i]; i++)
  11505. {
  11506. str[i] = tolower(str[i]);
  11507. }
  11508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11509. isSuccess = ConfigurationStatus_Accepted;
  11510. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11511. }
  11512. else
  11513. {
  11514. isSuccess = ConfigurationStatus_Rejected;
  11515. }
  11516. }
  11517. if(strcmp(key, "LocalPreAuthorize") == 0)
  11518. {
  11519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11520. {
  11521. strcpy(str, (const char*)value);
  11522. for(int i = 0; str[i]; i++)
  11523. {
  11524. str[i] = tolower(str[i]);
  11525. }
  11526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11527. isSuccess = ConfigurationStatus_Accepted;
  11528. }
  11529. else
  11530. {
  11531. isSuccess = ConfigurationStatus_Rejected;
  11532. }
  11533. }
  11534. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11535. {
  11536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11537. {
  11538. check_ascii = value[0];
  11539. if( (check_ascii < 48) || (check_ascii > 57) )
  11540. {
  11541. isSuccess = ConfigurationStatus_Rejected;
  11542. }
  11543. else
  11544. {
  11545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11546. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11547. isSuccess = ConfigurationStatus_Accepted;
  11548. }
  11549. }
  11550. else
  11551. {
  11552. isSuccess = ConfigurationStatus_Rejected;
  11553. }
  11554. }
  11555. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11556. {
  11557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11558. {
  11559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11560. isSuccess = ConfigurationStatus_Accepted;
  11561. }
  11562. else
  11563. {
  11564. isSuccess = ConfigurationStatus_Rejected;
  11565. }
  11566. }
  11567. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11568. {
  11569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11570. {
  11571. check_ascii = value[0];
  11572. if( (check_ascii < 48) || (check_ascii > 57) )
  11573. {
  11574. isSuccess = ConfigurationStatus_Rejected;
  11575. }
  11576. else
  11577. {
  11578. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11580. isSuccess = ConfigurationStatus_Accepted;
  11581. }
  11582. }
  11583. else
  11584. {
  11585. isSuccess = ConfigurationStatus_Rejected;
  11586. }
  11587. }
  11588. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11589. {
  11590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11591. {
  11592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11593. isSuccess = ConfigurationStatus_Accepted;
  11594. }
  11595. else
  11596. {
  11597. isSuccess = ConfigurationStatus_Rejected;
  11598. }
  11599. }
  11600. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11601. {
  11602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11603. {
  11604. check_ascii = value[0];
  11605. if( (check_ascii < 48) || (check_ascii > 57) )
  11606. {
  11607. isSuccess = ConfigurationStatus_Rejected;
  11608. }
  11609. else
  11610. {
  11611. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11613. isSuccess = ConfigurationStatus_Accepted;
  11614. }
  11615. }
  11616. else
  11617. {
  11618. isSuccess = ConfigurationStatus_Rejected;
  11619. }
  11620. }
  11621. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11622. {
  11623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11624. {
  11625. check_ascii = value[0];
  11626. if( (check_ascii < 48) || (check_ascii > 57) )
  11627. {
  11628. isSuccess = ConfigurationStatus_Rejected;
  11629. }
  11630. else
  11631. {
  11632. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11634. isSuccess = ConfigurationStatus_Accepted;
  11635. }
  11636. }
  11637. else
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. }
  11642. if(strcmp(key, "MinimumStatusDuration") == 0)
  11643. {
  11644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11645. {
  11646. check_ascii = value[0];
  11647. if( (check_ascii < 48) || (check_ascii > 57) )
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. else
  11652. {
  11653. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11654. {
  11655. isSuccess = ConfigurationStatus_Rejected;
  11656. }
  11657. else
  11658. {
  11659. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11661. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11662. isSuccess = ConfigurationStatus_Accepted;
  11663. }
  11664. }
  11665. }
  11666. else
  11667. {
  11668. isSuccess = ConfigurationStatus_Rejected;
  11669. }
  11670. }
  11671. if(strcmp(key, "NumberOfConnectors") == 0)
  11672. {
  11673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11674. {
  11675. check_ascii = value[0];
  11676. if( (check_ascii < 48) || (check_ascii > 57) )
  11677. {
  11678. isSuccess = ConfigurationStatus_Rejected;
  11679. }
  11680. else
  11681. {
  11682. //Charger.ResetRetries = Integer.parseInt(value);
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11684. isSuccess = ConfigurationStatus_Accepted;
  11685. }
  11686. }
  11687. else
  11688. {
  11689. isSuccess = ConfigurationStatus_Rejected;
  11690. }
  11691. }
  11692. if(strcmp(key, "ResetRetries") == 0)
  11693. {
  11694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11695. {
  11696. check_ascii = value[0];
  11697. if( (check_ascii < 48) || (check_ascii > 57) )
  11698. {
  11699. isSuccess = ConfigurationStatus_Rejected;
  11700. }
  11701. else
  11702. {
  11703. //Charger.ResetRetries = Integer.parseInt(value);
  11704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11705. isSuccess = ConfigurationStatus_Accepted;
  11706. }
  11707. }
  11708. else
  11709. {
  11710. isSuccess = ConfigurationStatus_Rejected;
  11711. }
  11712. }
  11713. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11714. {
  11715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11716. {
  11717. strcpy(str, (const char*)value);
  11718. for(int i = 0; str[i]; i++)
  11719. {
  11720. str[i] = tolower(str[i]);
  11721. }
  11722. if(strcmp(str, "notapplicable")== 0)
  11723. {
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. }
  11727. else if(strcmp(str, "unknown")== 0)
  11728. {
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11730. isSuccess = ConfigurationStatus_Accepted;
  11731. }
  11732. else if(strcmp(str, "rst")== 0)
  11733. {
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11735. isSuccess = ConfigurationStatus_Accepted;
  11736. }
  11737. else if(strcmp(str, "rts")== 0)
  11738. {
  11739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11740. isSuccess = ConfigurationStatus_Accepted;
  11741. }
  11742. else if(strcmp(str, "srt")== 0)
  11743. {
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11745. isSuccess = ConfigurationStatus_Accepted;
  11746. }
  11747. else if(strcmp(str, "str")== 0)
  11748. {
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11750. isSuccess = ConfigurationStatus_Accepted;
  11751. }
  11752. else if(strcmp(str, "trs")== 0)
  11753. {
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11755. isSuccess = ConfigurationStatus_Accepted;
  11756. }
  11757. else if(strcmp(str, "tsr")== 0)
  11758. {
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11760. isSuccess = ConfigurationStatus_Accepted;
  11761. }
  11762. else
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. }
  11767. else
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. }
  11772. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11773. {
  11774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11775. {
  11776. check_ascii = value[0];
  11777. if( (check_ascii < 48) || (check_ascii > 57) )
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. else
  11782. {
  11783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11784. isSuccess = ConfigurationStatus_Accepted;
  11785. }
  11786. }
  11787. else
  11788. {
  11789. isSuccess = ConfigurationStatus_Rejected;
  11790. }
  11791. }
  11792. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11793. {
  11794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11795. {
  11796. strcpy(str, (const char*)value);
  11797. for(int i = 0; str[i]; i++)
  11798. {
  11799. str[i] = tolower(str[i]);
  11800. }
  11801. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11803. isSuccess = ConfigurationStatus_Accepted;
  11804. }
  11805. else
  11806. {
  11807. isSuccess = ConfigurationStatus_Rejected;
  11808. }
  11809. }
  11810. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11811. {
  11812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11813. {
  11814. strcpy(str, (const char*)value);
  11815. for(int i = 0; str[i]; i++)
  11816. {
  11817. str[i] = tolower(str[i]);
  11818. }
  11819. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11821. isSuccess = ConfigurationStatus_Accepted;
  11822. }
  11823. else
  11824. {
  11825. isSuccess = ConfigurationStatus_Rejected;
  11826. }
  11827. }
  11828. if(strcmp(key, "StopTxnAlignedData") == 0)
  11829. {
  11830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11831. {
  11832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11833. isSuccess = ConfigurationStatus_Accepted;
  11834. }
  11835. else
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. }
  11840. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11841. {
  11842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11843. {
  11844. check_ascii = value[0];
  11845. if( (check_ascii < 48) || (check_ascii > 57) )
  11846. {
  11847. isSuccess = ConfigurationStatus_Rejected;
  11848. }
  11849. else
  11850. {
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "StopTxnSampledData") == 0)
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11863. {
  11864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11865. isSuccess = ConfigurationStatus_Accepted;
  11866. }
  11867. else
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. }
  11872. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11873. {
  11874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11875. {
  11876. check_ascii = value[0];
  11877. if( (check_ascii < 48) || (check_ascii > 57) )
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. else
  11882. {
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11884. isSuccess = ConfigurationStatus_Accepted;
  11885. }
  11886. }
  11887. else
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. }
  11892. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11895. {
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11897. isSuccess = ConfigurationStatus_Accepted;
  11898. }
  11899. else
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. }
  11904. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11905. {
  11906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11907. {
  11908. check_ascii = value[0];
  11909. if( (check_ascii < 48) || (check_ascii > 57) )
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. else
  11914. {
  11915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11916. isSuccess = ConfigurationStatus_Accepted;
  11917. }
  11918. }
  11919. else
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. }
  11924. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11925. {
  11926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11927. {
  11928. check_ascii = value[0];
  11929. if( (check_ascii < 48) || (check_ascii > 57) )
  11930. {
  11931. isSuccess = ConfigurationStatus_Rejected;
  11932. }
  11933. else
  11934. {
  11935. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11937. TransactionMessageAttemptsValue = atoi(value);
  11938. isSuccess = ConfigurationStatus_Accepted;
  11939. }
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11947. {
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11959. TransactionMessageRetryIntervalValue = atoi(value);
  11960. isSuccess = ConfigurationStatus_Accepted;
  11961. }
  11962. }
  11963. else
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. }
  11968. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11969. {
  11970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11971. {
  11972. strcpy(str, (const char*)value);
  11973. for(int i = 0; str[i]; i++)
  11974. {
  11975. str[i] = tolower(str[i]);
  11976. }
  11977. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11979. isSuccess = ConfigurationStatus_Accepted;
  11980. }
  11981. else
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. }
  11986. if(strcmp(key, "WebSocketPingInterval") == 0)
  11987. {
  11988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11989. {
  11990. check_ascii = value[0];
  11991. if( (check_ascii < 48) || (check_ascii > 57) )
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. else
  11996. {
  11997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11998. isSuccess = ConfigurationStatus_Accepted;
  11999. }
  12000. }
  12001. else
  12002. {
  12003. isSuccess = ConfigurationStatus_Rejected;
  12004. }
  12005. }
  12006. #if 0
  12007. //For OCPP Test Case
  12008. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12011. {
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. #endif
  12022. #if 1
  12023. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12024. {
  12025. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12026. {
  12027. strcpy(str, (const char*)value);
  12028. for(int i = 0; str[i]; i++)
  12029. {
  12030. str[i] = tolower(str[i]);
  12031. }
  12032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12033. isSuccess = ConfigurationStatus_Accepted;
  12034. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12035. }
  12036. else
  12037. {
  12038. isSuccess = ConfigurationStatus_Rejected;
  12039. }
  12040. }
  12041. #endif
  12042. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12043. {
  12044. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12045. {
  12046. check_ascii = value[0];
  12047. if( (check_ascii < 48) || (check_ascii > 57) )
  12048. {
  12049. isSuccess = ConfigurationStatus_Rejected;
  12050. }
  12051. else
  12052. {
  12053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12054. isSuccess = ConfigurationStatus_Accepted;
  12055. }
  12056. }
  12057. else
  12058. {
  12059. isSuccess = ConfigurationStatus_Rejected;
  12060. }
  12061. }
  12062. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12063. {
  12064. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12065. {
  12066. check_ascii = value[0];
  12067. if( (check_ascii < 48) || (check_ascii > 57) )
  12068. {
  12069. isSuccess = ConfigurationStatus_Rejected;
  12070. }
  12071. else
  12072. {
  12073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12074. isSuccess = ConfigurationStatus_Accepted;
  12075. }
  12076. }
  12077. else
  12078. {
  12079. isSuccess = ConfigurationStatus_Rejected;
  12080. }
  12081. }
  12082. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12083. {
  12084. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12085. {
  12086. strcpy(str, (const char*)value);
  12087. for(int i = 0; str[i]; i++)
  12088. {
  12089. str[i] = tolower(str[i]);
  12090. }
  12091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12092. isSuccess = ConfigurationStatus_Accepted;
  12093. }
  12094. else
  12095. {
  12096. isSuccess = ConfigurationStatus_Rejected;
  12097. }
  12098. }
  12099. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12100. {
  12101. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12102. {
  12103. check_ascii = value[0];
  12104. if( (check_ascii < 48) || (check_ascii > 57) )
  12105. {
  12106. isSuccess = ConfigurationStatus_Rejected;
  12107. }
  12108. else
  12109. {
  12110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12111. isSuccess = ConfigurationStatus_Accepted;
  12112. }
  12113. }
  12114. else
  12115. {
  12116. isSuccess = ConfigurationStatus_Rejected;
  12117. }
  12118. }
  12119. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12120. {
  12121. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12122. {
  12123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12124. isSuccess = ConfigurationStatus_Accepted;
  12125. }
  12126. else
  12127. {
  12128. isSuccess = ConfigurationStatus_Rejected;
  12129. }
  12130. }
  12131. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12132. {
  12133. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12134. {
  12135. check_ascii = value[0];
  12136. if( (check_ascii < 48) || (check_ascii > 57) )
  12137. {
  12138. isSuccess = ConfigurationStatus_Rejected;
  12139. }
  12140. else
  12141. {
  12142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12143. isSuccess = ConfigurationStatus_Accepted;
  12144. }
  12145. }
  12146. else
  12147. {
  12148. isSuccess = ConfigurationStatus_Rejected;
  12149. }
  12150. }
  12151. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12152. {
  12153. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12154. {
  12155. strcpy(str, (const char*)value);
  12156. for(int i = 0; str[i]; i++)
  12157. {
  12158. str[i] = tolower(str[i]);
  12159. }
  12160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12161. isSuccess = ConfigurationStatus_Accepted;
  12162. }
  12163. else
  12164. {
  12165. isSuccess = ConfigurationStatus_Rejected;
  12166. }
  12167. }
  12168. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12169. {
  12170. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12171. {
  12172. check_ascii = value[0];
  12173. if( (check_ascii < 48) || (check_ascii > 57) )
  12174. {
  12175. isSuccess = ConfigurationStatus_Rejected;
  12176. }
  12177. else
  12178. {
  12179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12180. isSuccess = ConfigurationStatus_Accepted;
  12181. }
  12182. }
  12183. else
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. }
  12188. return isSuccess;
  12189. }
  12190. int updateSetting(char *key, char *value)
  12191. {
  12192. mtrace();
  12193. int isSuccess = FALSE;
  12194. char string[1000]={0}, buffer[1000]={0};
  12195. char strtemp[50]={0};
  12196. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12197. int pos, c = 0;
  12198. char *loc;
  12199. int pos1=0;
  12200. FILE *f = fopen("/var/www/settings1", "r");
  12201. if(f == NULL)
  12202. {
  12203. #ifdef Debug
  12204. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12205. #endif
  12206. return isSuccess;
  12207. }
  12208. fseek(f, 0, SEEK_END);
  12209. long fsize = ftell(f);
  12210. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12211. fread(string, 1, fsize, f);
  12212. fclose(f);
  12213. string[fsize] = 0;
  12214. loc = strstr(string, key);
  12215. if(loc != NULL)
  12216. {
  12217. DEBUG_INFO("key exist!\n");
  12218. pos = loc - string-1;
  12219. f = fopen("/var/www/settings1", "w");
  12220. strncpy(buffer, string, pos);
  12221. fprintf(f, "%s", buffer);
  12222. memset(sstr ,0, sizeof(sstr) );
  12223. c = 0;
  12224. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12225. {
  12226. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12228. c++;
  12229. }
  12230. sstr[c] = '\0';
  12231. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12232. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12233. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12234. memset(buffer ,0, sizeof(buffer) );
  12235. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12236. //printf("buffer=%s",buffer);
  12237. fprintf(f, "%s", buffer);
  12238. fclose(f);
  12239. }
  12240. else
  12241. {
  12242. printf("key not exist!\n");
  12243. f = fopen("/var/www/settings1", "w+");
  12244. fputs(string, f);
  12245. fseek(f, -1, SEEK_CUR);
  12246. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12247. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12248. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12249. fclose(f);
  12250. }
  12251. isSuccess = TRUE;
  12252. return isSuccess;
  12253. }
  12254. int TransactionMessageAttemptsGet(void)
  12255. {
  12256. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12257. }
  12258. int FirstHeartBeatResponse(void)
  12259. {
  12260. return FirstHeartBeat;
  12261. }
  12262. int TransactionMessageRetryIntervalGet(void)
  12263. {
  12264. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12265. }
  12266. #define SA struct sockaddr
  12267. #define MAXBUF 1024
  12268. //static int m_socket_data;
  12269. //static int sockfd;
  12270. int ReadHttpStatus(int sock){
  12271. //char c;
  12272. char buff[1024]="",*ptr=buff+1;
  12273. int bytes_received, status;
  12274. DEBUG_INFO("Begin Response ..\n");
  12275. while((bytes_received = recv(sock, ptr, 1, 0))){
  12276. if(bytes_received==-1){
  12277. perror("ReadHttpStatus");
  12278. exit(1);
  12279. }
  12280. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12281. ptr++;
  12282. }
  12283. *ptr=0;
  12284. ptr=buff+1;
  12285. sscanf(ptr,"%*s %d ", &status);
  12286. DEBUG_INFO("%s\n",ptr);
  12287. DEBUG_INFO("status=%d\n",status);
  12288. DEBUG_INFO("End Response ..\n");
  12289. return (bytes_received>0)?status:0;
  12290. }
  12291. //the only filed that it parsed is 'Content-Length'
  12292. int ParseHeader(int sock){
  12293. //char c;
  12294. char buff[1024]="",*ptr=buff+4;
  12295. int bytes_received;
  12296. DEBUG_INFO("Begin HEADER ..\n");
  12297. while((bytes_received = recv(sock, ptr, 1, 0))){
  12298. if(bytes_received==-1){
  12299. perror("Parse Header");
  12300. exit(1);
  12301. }
  12302. if(
  12303. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12304. (ptr[-1]=='\r') && (*ptr=='\n' )
  12305. ) break;
  12306. ptr++;
  12307. }
  12308. *ptr=0;
  12309. ptr=buff+4;
  12310. //printf("%s",ptr);
  12311. if(bytes_received){
  12312. ptr=strstr(ptr,"Content-Length:");
  12313. if(ptr){
  12314. sscanf(ptr,"%*s %d",&bytes_received);
  12315. }else
  12316. bytes_received=-1; //unknown size
  12317. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12318. }
  12319. DEBUG_INFO("End HEADER ..\n");
  12320. return bytes_received ;
  12321. }
  12322. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12323. {
  12324. char rmFileCmd[100]={0};
  12325. char FilePath[100]={0};
  12326. char ftpbuf[200];
  12327. int systemresult;
  12328. //DEBUG_INFO("filename=%s\n",filename);
  12329. //DEBUG_INFO("url=%s\n",url);
  12330. sprintf(FilePath,"/mnt/%s",filename);
  12331. if((access(FilePath,F_OK))!=-1)
  12332. {
  12333. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12334. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12335. system(rmFileCmd);
  12336. }
  12337. memset(ftpbuf, 0, sizeof(ftpbuf));
  12338. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12339. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12340. systemresult = system(ftpbuf);
  12341. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12342. if(systemresult != 0)
  12343. {
  12344. DEBUG_INFO("http DownLoad error!\n");
  12345. return FALSE;
  12346. }
  12347. return TRUE;
  12348. }
  12349. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12350. {
  12351. char rmFileCmd[100]={0};
  12352. char FilePath[100]={0};
  12353. char ftpbuf[200];
  12354. int systemresult;
  12355. //char temp[100];
  12356. #if 0
  12357. struct hostent* server;
  12358. char *IPbuffer;
  12359. server = gethostbyname(location);
  12360. // To convert an Internet network
  12361. // address into ASCII string
  12362. IPbuffer = inet_ntoa(*((struct in_addr*)
  12363. server->h_addr_list[0]));
  12364. #endif
  12365. sprintf(FilePath,"/mnt/%s",filename);
  12366. if((access(FilePath,F_OK))!=-1)
  12367. {
  12368. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12369. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12370. system(rmFileCmd);
  12371. }
  12372. memset(ftpbuf, 0, sizeof(ftpbuf));
  12373. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12374. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12375. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12376. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12377. systemresult = system(ftpbuf);
  12378. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12379. if(systemresult != 0)
  12380. {
  12381. printf("wget error!\n");
  12382. return FALSE;
  12383. }
  12384. return TRUE;
  12385. }
  12386. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12387. {
  12388. char rmFileCmd[100]={0};
  12389. char FilePath[100]={0};
  12390. char ftpbuf[200];
  12391. char filenametemp[60]={0};
  12392. int systemresult;
  12393. //DEBUG_INFO("filename=%s\n",filename);
  12394. //DEBUG_INFO("url=%s\n",url);
  12395. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12396. if((access(FilePath,F_OK))!=-1)
  12397. {
  12398. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12399. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12400. system(rmFileCmd);
  12401. }
  12402. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12403. if(fp == NULL)
  12404. {
  12405. DEBUG_INFO("log is NULL\n");
  12406. return FALSE;
  12407. }
  12408. else
  12409. {
  12410. fprintf(fp, "%s\n", url);
  12411. sscanf(filename, "%*2[.]%s", filenametemp);
  12412. fprintf(fp, "%s\n", filenametemp);
  12413. fclose(fp);
  12414. }
  12415. memset(ftpbuf, 0, sizeof(ftpbuf));
  12416. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12417. systemresult = system(ftpbuf);
  12418. DEBUG_INFO("systemresult=%d\n",systemresult);
  12419. if(systemresult != 0)
  12420. {
  12421. DEBUG_INFO("http upload error!\n");
  12422. return FALSE;
  12423. }
  12424. return TRUE;
  12425. }
  12426. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12427. {
  12428. struct hostent* server;
  12429. char *IPbuffer;
  12430. char ftpbuf[200];
  12431. int systemresult;
  12432. // To retrieve host information
  12433. server = gethostbyname(location);
  12434. // To convert an Internet network
  12435. // address into ASCII string
  12436. IPbuffer = inet_ntoa(*((struct in_addr*)
  12437. server->h_addr_list[0]));
  12438. memset(ftpbuf, 0, sizeof(ftpbuf));
  12439. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12440. /* format : ftpput -u username -p passwd IP target source*/
  12441. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12442. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12443. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12444. systemresult = system(ftpbuf);
  12445. DEBUG_INFO("systemresult=%d\n",systemresult);
  12446. if(systemresult != 0)
  12447. {
  12448. DEBUG_INFO("ftpput error!\n");
  12449. return FALSE;
  12450. }
  12451. return TRUE;
  12452. }
  12453. int SettingChargingRecord(int target, int transactionId)
  12454. {
  12455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12456. {
  12457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12458. {
  12459. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12460. {
  12461. addBuff(target, transactionId, 0);
  12462. return TRUE;
  12463. }
  12464. }
  12465. for (int index = 0; index < CCS_QUANTITY; index++)
  12466. {
  12467. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12468. {
  12469. addBuff(target, transactionId, 0);
  12470. return TRUE;
  12471. }
  12472. }
  12473. for (int index = 0; index < GB_QUANTITY; index++)
  12474. {
  12475. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12476. {
  12477. addBuff(target, transactionId, 0);
  12478. return TRUE;
  12479. }
  12480. }
  12481. }
  12482. else
  12483. {
  12484. for (int index = 0; index < AC_QUANTITY; index++)
  12485. {
  12486. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12487. {
  12488. addBuff(target, transactionId, 0);
  12489. return TRUE;
  12490. }
  12491. }
  12492. }
  12493. return FALSE;
  12494. }
  12495. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12496. {
  12497. int isSuccess = FALSE;
  12498. //char *query = NULL;
  12499. sqlite3_stmt *stmt;
  12500. int rc; // return code
  12501. char str[20];
  12502. sprintf(str,"%d",user_id);
  12503. sqlite3_prepare_v2(db, "insert into log_buffer (user_id, cmd_sn, charger_id, gun_type, gun_no, rfid_no, stime, etime, time_len, s_soc, e_soc, stop_reason, power, meter_before, meter_after, charge_price, reserve, surplus_before, surplus_after, service_price, is_pay ,charge_strategy, charge_parameter, vin, vehicle_no, start_method, card_type, is_upload, guid, is_buf2OK) values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30);", -1, &stmt, NULL); /* 1 */
  12504. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12505. rc = sqlite3_step(stmt); /* 3 */
  12506. if (rc != SQLITE_DONE) {
  12507. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12508. goto out;
  12509. }
  12510. sqlite3_finalize(stmt);
  12511. // free(query);
  12512. out:
  12513. //----------------------
  12514. // close SQLite database
  12515. //----------------------
  12516. sqlite3_close(db);
  12517. printf("database closed.\n");
  12518. return isSuccess;
  12519. }
  12520. /**
  12521. * Place the contents of the specified file into a memory buffer
  12522. *
  12523. * @param[in] filename The path and name of the file to read
  12524. * @param[out] filebuffer A pointer to the contents in memory
  12525. * @return status 0 success, 1 on failure
  12526. */
  12527. int get_file_contents(const char* filename, char** outbuffer) {
  12528. FILE* file = NULL;
  12529. long filesize;
  12530. const int blocksize = 1;
  12531. size_t readsize;
  12532. char* filebuffer;
  12533. // Open the file
  12534. file = fopen(filename, "r");
  12535. if (NULL == file)
  12536. {
  12537. printf("'%s' not opened\n", filename);
  12538. exit(EXIT_FAILURE);
  12539. }
  12540. // Determine the file size
  12541. fseek(file, 0, SEEK_END);
  12542. filesize = ftell(file);
  12543. rewind (file);
  12544. // Allocate memory for the file contents
  12545. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12546. *outbuffer = filebuffer;
  12547. if (filebuffer == NULL)
  12548. {
  12549. fputs ("malloc out-of-memory", stderr);
  12550. exit(EXIT_FAILURE);
  12551. }
  12552. // Read in the file
  12553. readsize = fread(filebuffer, blocksize, filesize, file);
  12554. if (readsize != filesize)
  12555. {
  12556. fputs ("didn't read file completely",stderr);
  12557. exit(EXIT_FAILURE);
  12558. }
  12559. // Clean exit
  12560. fclose(file);
  12561. return EXIT_SUCCESS;
  12562. }
  12563. static int selectSqlCount = 0;
  12564. static int callback(void *data, int argc, char **argv, char **azColName){
  12565. int i;
  12566. //printf("%s: ", (const char*)data);
  12567. selectSqlCount = argc;
  12568. for(i = 0; i<argc; i++){
  12569. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12570. }
  12571. //printf("\n");
  12572. return 0;
  12573. }
  12574. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12575. //int i;
  12576. //printf("%s:\n", (const char*)data);
  12577. localversion = argv[5] ? atoi(argv[5]) : 0;
  12578. //printf("localversion=%d\n", localversion);
  12579. return 0;
  12580. }
  12581. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12582. //int i;
  12583. //printf("%s:\n", (const char*)data);
  12584. //idTag
  12585. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12586. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12587. //parentIdTag
  12588. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12589. //expir_date
  12590. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12591. //status
  12592. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12593. //version
  12594. idTagQuery.listVersionInt = atoi(argv[5]);
  12595. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12596. return 0;
  12597. }
  12598. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12599. #if 0
  12600. int i;
  12601. //printf("%s:\n", (const char*)data);
  12602. for(i=0; i<argc; i++){
  12603. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12604. }
  12605. //printf("");
  12606. #endif
  12607. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12608. // printf("localversion=%d\n", localversion);
  12609. return 0;
  12610. }
  12611. /** sqlite3_exec的回调。
  12612. *
  12613. * 向控制台打印查询的结果。
  12614. *
  12615. * @param in data 传递给回调函数的数据。
  12616. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12617. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12618. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12619. * @return 状态码。
  12620. */
  12621. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12622. {
  12623. for (int i = 0; i < n_columns; i++)
  12624. {
  12625. DEBUG_INFO("%s/t", col_values[i]);
  12626. }
  12627. DEBUG_INFO("/n");
  12628. return 0;
  12629. }
  12630. void OCPP_getListVerion()
  12631. {
  12632. int rc = 0;
  12633. // const char* data = "Callback function called";
  12634. char sql[100];
  12635. char zErrMsg[100];
  12636. memset(sql, 0, 100);
  12637. memset(zErrMsg, 0, 100);
  12638. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12639. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12640. /* Execute SQL statement */
  12641. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12642. DEBUG_INFO("rc=%d\n",rc);
  12643. if( rc != SQLITE_OK ){
  12644. DEBUG_INFO("SQL error: %s", zErrMsg);
  12645. //sqlite3_free(zErrMsg);
  12646. }
  12647. }
  12648. void OCPP_getIdTag(char idTag[])
  12649. {
  12650. int rc = 0;
  12651. // const char* data = "Callback function called";
  12652. char sql[100];
  12653. char zErrMsg[100];
  12654. memset(sql, 0, 100);
  12655. memset(zErrMsg, 0, 100);
  12656. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12657. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12658. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12659. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12660. /* Execute SQL statement */
  12661. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12662. if( rc != SQLITE_OK ){
  12663. DEBUG_INFO("SQL error: %s", zErrMsg);
  12664. //sqlite3_free(zErrMsg);
  12665. }
  12666. //return ver;
  12667. }
  12668. void OCPP_get_TableAuthlocalAllData(void)
  12669. {
  12670. int rc = 0;
  12671. // const char* data = "Callback function called";
  12672. char sql[100];
  12673. char zErrMsg[100];
  12674. memset(sql, 0, 100);
  12675. memset(zErrMsg, 0, 100);
  12676. sprintf(sql,"select * from ocpp_auth_local ");
  12677. /* Execute SQL statement */
  12678. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12679. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12680. if( rc != SQLITE_OK ){
  12681. DEBUG_INFO("SQL error: %s", zErrMsg);
  12682. //sqlite3_free(zErrMsg);
  12683. }
  12684. //return ver;
  12685. }
  12686. int OCPP_cleanLocalList()
  12687. {
  12688. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12689. char *errMsg = 0;
  12690. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12691. if (SQLITE_OK != rc)
  12692. {
  12693. DEBUG_INFO("%s\n",errMsg);
  12694. return FALSE;
  12695. }
  12696. else
  12697. {
  12698. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12699. }
  12700. return TRUE;
  12701. }
  12702. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12703. {
  12704. int isSuccess = FALSE;
  12705. int ret = 0;
  12706. //const char* data = "Callback function called";
  12707. char sql[300];
  12708. char zErrMsg[200];
  12709. memset(sql, 0, 300);
  12710. memset(zErrMsg, 0, 200);
  12711. 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);
  12712. //* Execute SQL statement */
  12713. //zErrMsg = 0;
  12714. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12715. if( ret != SQLITE_OK ){
  12716. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12717. // free(zErrMsg);
  12718. // free(sql);
  12719. return isSuccess;
  12720. }
  12721. memset(sql, 0, 300);
  12722. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12723. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12724. if( ret != SQLITE_OK ){
  12725. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12726. // free(zErrMsg);
  12727. // free(sql);
  12728. return isSuccess;
  12729. }
  12730. // DEBUG_INFO("successfully Insert records created\n");
  12731. isSuccess = TRUE;
  12732. return isSuccess;
  12733. }
  12734. void OCPP_deleteIdTag(char idTag[])
  12735. {
  12736. //int ver = 0;
  12737. //int isSuccess = FALSE;
  12738. int rc = 0;
  12739. char sql[100];
  12740. char zErrMsg[100];
  12741. memset(sql, 0, 100);
  12742. memset(zErrMsg, 0, 100);
  12743. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12744. //* Execute SQL statement */
  12745. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12746. if( rc != SQLITE_OK ){
  12747. DEBUG_INFO("SQL error: %s", zErrMsg);
  12748. //sqlite3_free(zErrMsg);
  12749. }
  12750. }
  12751. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12752. {
  12753. int isSuccess = FALSE;
  12754. int ret = 0;
  12755. const char* data = "Callback function called";
  12756. char sql[200];
  12757. char zErrMsg[100];
  12758. memset(sql, 0, 200);
  12759. memset(zErrMsg, 0, 100);
  12760. //* selectFromTable */
  12761. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12762. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12763. //* Execute SQL statement */
  12764. selectSqlCount = 0;
  12765. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12766. if( ret != SQLITE_OK ){
  12767. printf("Error SQL: %s\n", zErrMsg);
  12768. }
  12769. printf("successfully select operation done\n");
  12770. memset(sql, 0, 200);
  12771. memset(zErrMsg, 0, 100);
  12772. if(selectSqlCount == 0)
  12773. {
  12774. //Insert
  12775. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12776. sprintf(sql,"INSERT INTO ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ", idTag, parentTage, expiryDate, status, version);
  12777. DEBUG_INFO("sql:%s\n", sql);
  12778. //* Execute SQL statement */
  12779. //zErrMsg = 0;
  12780. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12781. if( ret != SQLITE_OK ){
  12782. printf("SQL error: %s\n", zErrMsg);
  12783. return isSuccess;
  12784. }
  12785. DEBUG_INFO("successfully Insert records created\n");
  12786. isSuccess = TRUE;
  12787. }
  12788. else
  12789. {
  12790. //Update
  12791. //* Create merged SQL statement */
  12792. sprintf(sql, "UPDATE ocpp_auth_local set parent_idtag = '%s', expir_date = '%s', status ='%s', version =%d where idtag='%s'; " "SELECT * from ocpp_auth_local", parentTage, expiryDate, status, version, idTag);
  12793. /* Execute SQL statement */
  12794. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12795. if( ret != SQLITE_OK ){
  12796. printf("SQL error: %s\n", zErrMsg);
  12797. //sqlite3_free(zErrMsg);
  12798. //sqlite3_free(sql);
  12799. return isSuccess;
  12800. }
  12801. DEBUG_INFO("Successfully operation done \n");
  12802. isSuccess = TRUE;
  12803. }
  12804. return isSuccess;
  12805. }
  12806. int GetOcppServerURL()
  12807. {
  12808. int result = FALSE;
  12809. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12810. memset(OcppHost, 0, sizeof(OcppHost));
  12811. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12812. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12813. {
  12814. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12815. #if 1
  12816. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12817. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12818. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12819. #endif
  12820. #if 0
  12821. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12822. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  12823. OcppProtocol, OcppHost, OcppTempPath);
  12824. OcppPort = 443;
  12825. #endif
  12826. result = TRUE;
  12827. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12828. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12829. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12830. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12831. goto End;
  12832. }
  12833. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12834. {
  12835. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12836. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12837. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12838. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12839. result = TRUE;
  12840. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12841. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12842. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12843. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12844. goto End;
  12845. }
  12846. else
  12847. {
  12848. strcpy(OcppHost,"");
  12849. }
  12850. End:
  12851. return result;
  12852. }
  12853. int GetOcppPath()
  12854. {
  12855. int result = FALSE;
  12856. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12857. {
  12858. if(OcppTempPath == NULL)
  12859. {
  12860. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12861. }
  12862. else
  12863. {
  12864. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12865. }
  12866. result = TRUE;
  12867. goto End;
  12868. }
  12869. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12870. {
  12871. if(OcppTempPath == NULL)
  12872. {
  12873. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12874. }
  12875. else
  12876. {
  12877. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12878. }
  12879. result = TRUE;
  12880. goto End;
  12881. }
  12882. else
  12883. {
  12884. strcpy(OcppPath,"");
  12885. }
  12886. End:
  12887. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12888. return result;
  12889. }
  12890. int GetOcppPort()
  12891. {
  12892. return OcppPort;
  12893. }
  12894. int GetOcppConnStatus(void)
  12895. {
  12896. return ShmOCPP16Data->OcppConnStatus;
  12897. }
  12898. void SetOcppConnStatus(uint8_t status)
  12899. {
  12900. ShmOCPP16Data->OcppConnStatus = status;
  12901. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12902. if(status == FALSE)
  12903. {
  12904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12905. {
  12906. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12907. }
  12908. else
  12909. {
  12910. SystemInitial = AC_QUANTITY;
  12911. }
  12912. }
  12913. }
  12914. int GetHeartBeatWithNOResponse(void)
  12915. {
  12916. return HeartBeatWithNOResponse;
  12917. }
  12918. void SetHeartBeatWithNOResponse(void)
  12919. {
  12920. HeartBeatWithNOResponse = 0;
  12921. }
  12922. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12923. /*
  12924. src 源字串的首地址(buf的地址)
  12925. separator 指定的分割字元
  12926. dest 接收子字串的陣列
  12927. num 分割後子字串的個數
  12928. */
  12929. char *pNext;
  12930. int count = 0;
  12931. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12932. return;
  12933. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12934. return;
  12935. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12936. while(pNext != NULL) {
  12937. *dest++ = pNext;
  12938. ++count;
  12939. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12940. }
  12941. *num = count;
  12942. }
  12943. int GetTransactionId(int gunindex, unsigned char idTag[])
  12944. {
  12945. char ch;
  12946. FILE *fptr1;
  12947. int temptransactionId;
  12948. char str[100]={0};
  12949. temptransactionId = 0;
  12950. /*------ Read the file ----------------*/
  12951. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12952. if (!fptr1)
  12953. {
  12954. printf(" File not found or unable to open the input file!!\n");
  12955. return temptransactionId;
  12956. }
  12957. ch=fgetc(fptr1);
  12958. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12959. rewind(fptr1);
  12960. if(ch!=EOF)
  12961. {
  12962. // printf("%c",ch);
  12963. while (fgets(str, 100, fptr1) != NULL)
  12964. {
  12965. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12966. if(str[0]=='\0')
  12967. {
  12968. break;
  12969. }
  12970. char *revbuf[8] = {0}; //存放分割後的子字串
  12971. int num = 0;//分割後子字串的個數
  12972. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12973. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12974. {
  12975. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12976. {
  12977. temptransactionId = atoi(revbuf[2]);
  12978. break;
  12979. }
  12980. }
  12981. }
  12982. }
  12983. fclose(fptr1);
  12984. /*------- End of reading ---------------*/
  12985. return temptransactionId;
  12986. }
  12987. void SetTransactionIdZero(int transactionId)
  12988. {
  12989. //TransactionId[gunindex] = 0;
  12990. char ch;
  12991. FILE *fptr1, *fptr2;
  12992. int temptransactionId = 0;
  12993. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12994. printf("\n\n Delete a specific line from a file :\n");
  12995. printf("-----------------------------------------\n");
  12996. //scanf("%s",fname);
  12997. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12998. if (!fptr1)
  12999. {
  13000. printf(" File not found or unable to open the input file!!\n");
  13001. return ;
  13002. }
  13003. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13004. if (!fptr2)
  13005. {
  13006. printf("Unable to open a temporary file to write!!\n");
  13007. fclose(fptr1);
  13008. return ;
  13009. }
  13010. ch=fgetc(fptr1);
  13011. //printf(" Now the content of the file %s is : \n",fname);
  13012. rewind(fptr1);
  13013. if(ch!=EOF)
  13014. {
  13015. // copy all contents to the temporary file except the specific line
  13016. while (fgets(str, 100, fptr1) != NULL)
  13017. {
  13018. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13019. if(str[0]=='\0')
  13020. {
  13021. break;
  13022. }
  13023. char *revbuf[8] = {0}; //存放分割後的子字串
  13024. int num = 0;//分割後子字串的個數
  13025. strcpy(strtemp, str);
  13026. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13027. if(revbuf[2][0] != '\0')
  13028. {
  13029. temptransactionId = atoi(revbuf[2]);
  13030. if(transactionId != temptransactionId)
  13031. {
  13032. fprintf(fptr2, "%s", strtemp);
  13033. }
  13034. }
  13035. }
  13036. }
  13037. fclose(fptr1);
  13038. fclose(fptr2);
  13039. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13040. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13041. /*------ Read the file ----------------*/
  13042. }
  13043. int InternetDisconnect(void)
  13044. {
  13045. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13046. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13047. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13048. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13049. }
  13050. void GetChargingProfileRequest(int gunindex)
  13051. {
  13052. mtrace();
  13053. //int connectorIdInt, durationInt;
  13054. //char chargingRateUnitStr[4]={0};
  13055. int tempdurationInt = 0;
  13056. int tempchargingProfileId = 0;
  13057. int tempstackLevel = 0;
  13058. int temptransactionId = 0;
  13059. float tempminChargingRateFloat = 0.0;
  13060. char tempchargingProfilePurposeStr[24]={0};
  13061. char tempchargingProfileKindStr[12]={0};
  13062. char temprecurrencyKindStr[8]={0};
  13063. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13064. char tempvalidToStr[28]={0};
  13065. int tempStartPeriodInt = 0;
  13066. float tempLimitInt = 0.0;//0.1;
  13067. int tempNumberPhasesInt=0;
  13068. char fname[200];
  13069. //char comfirmstr[20];
  13070. float MinChargingRate =0.0;
  13071. double diff_t;
  13072. struct tm tp;
  13073. FILE *fptr1;//, *fptr2;
  13074. int c = 0;
  13075. char * pch;
  13076. char *loc;
  13077. char sstr[200]={ 0 };
  13078. int n_chargingProfile = 0;
  13079. int n_SchedulePeriods = 0;
  13080. char SchedulePeriodList[10][200]={0};
  13081. char sLineWord[1600]={0};
  13082. char word[1000]={0};
  13083. int confirmPeriods = 0;
  13084. struct StructProfile ChargePointMaxProfile;
  13085. struct StructProfile TxDefaultProfile;
  13086. struct StructProfile TxProfile;
  13087. struct StructProfile TxDefaultProfiletemp[2]={0};
  13088. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13089. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13090. struct StructChargingProfile TxProfile_TEMP={0};
  13091. int TxDefaultProfileFileIsNull=FALSE;
  13092. int ChargePointMaxProfileIsNull=FALSE;
  13093. int TxProfileIsNull=FALSE;
  13094. // int CompositeSceduleIndex = 0;
  13095. char ChargePointMaxProfileScheduleStr[30]={0};
  13096. char TxDefaultProfileScheduleStr[30]={0};
  13097. char TxProfileScheduleStr[30]={0};
  13098. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13099. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13100. memset(&TxProfile,0,sizeof(struct StructProfile));
  13101. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13102. DEBUG_INFO("GetChargingProfileRequest\n");
  13103. //*****************************ChargePointMaxProfile******************************************/
  13104. strcpy(fname, ChargePointMaxProfile_JSON);
  13105. ChargePointMaxProfileIsNull=TRUE;
  13106. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13107. {
  13108. fptr1 = fopen(fname, "r");
  13109. int c;
  13110. c = fgetc(fptr1);
  13111. //DEBUG_INFO("c:%d\n",c);
  13112. rewind(fptr1);
  13113. if(c == EOF)
  13114. {
  13115. DEBUG_INFO("\n End of file reached.");
  13116. ChargePointMaxProfileIsNull=TRUE;
  13117. fclose(fptr1);
  13118. }
  13119. else
  13120. {
  13121. ChargePointMaxProfileIsNull=FALSE;
  13122. while(fscanf(fptr1, "%s", word) != EOF)
  13123. {
  13124. if(strcmp(word, "chargingProfileId") == 0)
  13125. {
  13126. n_chargingProfile = n_chargingProfile + 1;
  13127. }
  13128. }
  13129. rewind(fptr1);
  13130. //search Charging Profile Element
  13131. int i = 0;
  13132. int j = 0;
  13133. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13134. //***********chargingProfileId**************/
  13135. c = 0;
  13136. loc = strstr(sLineWord, "chargingProfileId");
  13137. //DEBUG_INFO("loc=%s\n",loc);
  13138. memset(sstr ,0, sizeof(sstr) );
  13139. if(loc != NULL)
  13140. {
  13141. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13142. {
  13143. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13145. c++;
  13146. }
  13147. sstr[c] = '\0';
  13148. tempchargingProfileId = atoi(sstr);
  13149. }
  13150. else
  13151. {
  13152. tempchargingProfileId = 0;
  13153. }
  13154. //***********stackLevel**************/
  13155. c = 0;
  13156. loc = strstr(sLineWord, "stackLevel");
  13157. //DEBUG_INFO("loc=%s\n",loc);
  13158. memset(sstr ,0, sizeof(sstr) );
  13159. if(loc != NULL)
  13160. {
  13161. while (loc[2+strlen("stackLevel")+c] != '\"')
  13162. {
  13163. sstr[c] = loc[2+strlen("stackLevel")+c];
  13164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13165. c++;
  13166. }
  13167. sstr[c] = '\0';
  13168. tempstackLevel = atoi(sstr);
  13169. }
  13170. else
  13171. {
  13172. tempstackLevel = 0;
  13173. }
  13174. //***********chargingProfilePurpose **************/
  13175. c = 0;
  13176. loc = strstr(sLineWord, "chargingProfilePurpose");
  13177. //DEBUG_INFO("loc=%s\n",loc);
  13178. memset(sstr ,0, sizeof(sstr) );
  13179. if(loc != NULL)
  13180. {
  13181. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13182. {
  13183. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13184. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13185. c++;
  13186. }
  13187. sstr[c] = '\0';
  13188. strcpy(tempchargingProfilePurposeStr,sstr);
  13189. }
  13190. else
  13191. {
  13192. strcpy(tempchargingProfilePurposeStr,"");
  13193. }
  13194. //***********chargingProfileKind **************/
  13195. c = 0;
  13196. loc = strstr(sLineWord, "chargingProfileKind");
  13197. //DEBUG_INFO("loc=%s\n",loc);
  13198. memset(sstr ,0, sizeof(sstr) );
  13199. if(loc != NULL)
  13200. {
  13201. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13202. {
  13203. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13205. c++;
  13206. }
  13207. sstr[c] = '\0';
  13208. strcpy(tempchargingProfileKindStr,sstr);
  13209. }
  13210. else
  13211. {
  13212. strcpy(tempchargingProfileKindStr,"");
  13213. }
  13214. //***********recurrencyKind **************/
  13215. c = 0;
  13216. loc = strstr(sLineWord, "recurrencyKind");
  13217. //DEBUG_INFO("loc=%s\n",loc);
  13218. memset(sstr ,0, sizeof(sstr) );
  13219. if(loc != NULL)
  13220. {
  13221. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13222. {
  13223. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13224. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13225. c++;
  13226. }
  13227. sstr[c] = '\0';
  13228. strcpy(temprecurrencyKindStr,sstr);
  13229. }
  13230. else
  13231. {
  13232. strcpy(temprecurrencyKindStr,"");
  13233. }
  13234. //***********validFrom**************/
  13235. c = 0;
  13236. loc = strstr(sLineWord, "validFrom");
  13237. //DEBUG_INFO("loc=%s\n",loc);
  13238. memset(sstr ,0, sizeof(sstr) );
  13239. if(loc != NULL)
  13240. {
  13241. while (loc[3+strlen("validFrom")+c] != '\"')
  13242. {
  13243. sstr[c] = loc[3+strlen("validFrom")+c];
  13244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. strcpy(tempvalidFromStr,sstr);
  13249. }
  13250. else
  13251. {
  13252. strcpy(tempvalidFromStr,"");
  13253. }
  13254. //***********validTo **************/
  13255. c = 0;
  13256. loc = strstr(sLineWord, "validTo");
  13257. //DEBUG_INFO("loc=%s\n",loc);
  13258. memset(sstr ,0, sizeof(sstr) );
  13259. if(loc != NULL)
  13260. {
  13261. while (loc[3+strlen("validTo")+c] != '\"')
  13262. {
  13263. sstr[c] = loc[3+strlen("validTo")+c];
  13264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13265. c++;
  13266. }
  13267. sstr[c] = '\0';
  13268. strcpy(tempvalidToStr,sstr);
  13269. }
  13270. else
  13271. {
  13272. strcpy(tempvalidToStr,"");
  13273. }
  13274. //***********validFrom**************/
  13275. c = 0;
  13276. loc = strstr(sLineWord, "validFrom");
  13277. if(loc != NULL)
  13278. {
  13279. memset(sstr ,0, sizeof(sstr) );
  13280. while (loc[3+strlen("validFrom")+c] != '\"')
  13281. {
  13282. sstr[c] = loc[3+strlen("validFrom")+c];
  13283. c++;
  13284. }
  13285. sstr[c] = '\0';
  13286. strcpy(tempvalidFromStr,sstr);
  13287. }
  13288. else
  13289. {
  13290. strcpy(tempvalidFromStr,"");
  13291. }
  13292. //***********validTo **************/
  13293. c = 0;
  13294. loc = strstr(sLineWord, "validTo");
  13295. if(loc != NULL)
  13296. {
  13297. memset(sstr ,0, sizeof(sstr) );
  13298. while (loc[3+strlen("validTo")+c] != '\"')
  13299. {
  13300. sstr[c] = loc[3+strlen("validTo")+c];
  13301. c++;
  13302. }
  13303. sstr[c] = '\0';
  13304. strcpy(tempvalidToStr,sstr);
  13305. }
  13306. else
  13307. {
  13308. strcpy(tempvalidToStr,"");
  13309. }
  13310. //***********duration**************/
  13311. c = 0;
  13312. loc = strstr(sLineWord, "duration");
  13313. if(loc != NULL)
  13314. {
  13315. memset(sstr ,0, sizeof(sstr) );
  13316. while (loc[2+strlen("duration")+c] != ',')
  13317. {
  13318. sstr[c] = loc[2+strlen("duration")+c];
  13319. c++;
  13320. }
  13321. sstr[c] = '\0';
  13322. tempdurationInt = atoi(sstr);
  13323. }
  13324. else
  13325. {
  13326. tempdurationInt = 0;
  13327. }
  13328. //**********startSchedule**********/
  13329. c = 0;
  13330. loc = strstr(sLineWord, "startSchedule");
  13331. memset(sstr ,0, sizeof(sstr) );
  13332. while (loc[3+strlen("startSchedule")+c] != '\"')
  13333. {
  13334. sstr[c] = loc[3+strlen("startSchedule")+c];
  13335. c++;
  13336. }
  13337. sstr[c] = '\0';
  13338. strcpy(tempstartScheduleStr, sstr);
  13339. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13340. //**********chargingRateUnit**********/
  13341. c = 0;
  13342. loc = strstr(sLineWord, "chargingRateUnit");
  13343. memset(sstr ,0, sizeof(sstr) );
  13344. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13345. {
  13346. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13347. c++;
  13348. }
  13349. sstr[c] = '\0';
  13350. strcpy(tempchargingRateUnitStr, sstr);
  13351. //**********minChargingRate*******/
  13352. c = 0;
  13353. loc = strstr(sLineWord, "minChargingRate");
  13354. if(loc != NULL)
  13355. {
  13356. memset(sstr ,0, sizeof(sstr) );
  13357. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13358. {
  13359. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13360. c++;
  13361. }
  13362. sstr[c] = '\0';
  13363. tempminChargingRateFloat = atof(sstr);
  13364. }
  13365. else
  13366. {
  13367. tempminChargingRateFloat = 0.0;
  13368. }
  13369. //
  13370. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13371. tp.tm_isdst = -1;
  13372. time_t utc = mktime(&tp);
  13373. time_t t = time(NULL);
  13374. diff_t = difftime(t, utc);
  13375. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13376. //parsing strings to words
  13377. i = 0;
  13378. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13379. loc = loc+3+strlen("chargingSchedulePeriod");
  13380. pch = strtok(loc ,"{");
  13381. while (pch != NULL)
  13382. {
  13383. strcpy(SchedulePeriodList[i], pch);
  13384. pch = strtok (NULL, "{");
  13385. i = i + 1;
  13386. }
  13387. n_SchedulePeriods = i;
  13388. for(int i=0;i<n_SchedulePeriods;i++)
  13389. {
  13390. //*************startPeriod****************/
  13391. c = 0;
  13392. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13393. memset(sstr ,0, sizeof(sstr) );
  13394. while (loc[strlen("startPeriod")+2+c] != ',')
  13395. {
  13396. sstr[c] = loc[strlen("startPeriod")+2+c];
  13397. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13398. c++;
  13399. }
  13400. sstr[c] = '\0';
  13401. tempStartPeriodInt = atoi(sstr);
  13402. //*************limit****************/
  13403. c = 0;
  13404. loc = strstr(SchedulePeriodList[i], "limit");
  13405. memset(sstr ,0, sizeof(sstr) );
  13406. while (loc[strlen("limit")+2+c] != ',')
  13407. {
  13408. sstr[c] = loc[strlen("limit")+2+c];
  13409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13410. c++;
  13411. }
  13412. sstr[c] = '\0';
  13413. tempLimitInt = atof(sstr);
  13414. //*************numberPhases****************/
  13415. c = 0;
  13416. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13417. memset(sstr ,0, sizeof(sstr) );
  13418. while (loc[strlen("numberPhases")+2+c] != '}')
  13419. {
  13420. sstr[c] = loc[strlen("numberPhases")+2+c];
  13421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13422. c++;
  13423. }
  13424. sstr[c] = '\0';
  13425. tempNumberPhasesInt = atoi(sstr);
  13426. if(j == 0)
  13427. {
  13428. ChargePointMaxProfile.Duration = tempdurationInt;
  13429. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13430. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13431. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13432. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13433. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13434. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13435. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13436. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13437. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13438. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13439. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13440. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13441. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13442. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13443. }
  13444. }
  13445. if(MinChargingRate < tempminChargingRateFloat)
  13446. {
  13447. MinChargingRate = tempminChargingRateFloat;
  13448. }
  13449. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13450. if(confirmPeriods < n_SchedulePeriods)
  13451. {
  13452. confirmPeriods = n_SchedulePeriods;
  13453. }
  13454. j = j + 1;
  13455. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13456. fclose(fptr1);
  13457. }// end else
  13458. }// the end of access file ChargePointMaxProfile
  13459. //****************************TxDefaultProfile************************************************/
  13460. #if 0
  13461. switch(gunindex + 1)
  13462. {
  13463. case 0:
  13464. strcpy(fname, TxDefaultProfile_0_JSON );
  13465. break;
  13466. case 1:
  13467. strcpy(fname, TxDefaultProfile_1_JSON );
  13468. break;
  13469. case 2:
  13470. strcpy(fname, TxDefaultProfile_2_JSON );
  13471. break;
  13472. default:
  13473. strcpy(fname, TxDefaultProfile_1_JSON );
  13474. break;
  13475. }
  13476. #endif
  13477. memset(fname, 0, sizeof fname);
  13478. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13479. TxDefaultProfileFileIsNull=TRUE;
  13480. if((access(fname,F_OK))!=-1)
  13481. {
  13482. fptr1 = fopen(fname, "r");
  13483. c = 0;
  13484. c = fgetc(fptr1);
  13485. //DEBUG_INFO("c:%d\n",c);
  13486. rewind(fptr1);
  13487. if(c == EOF)
  13488. {
  13489. DEBUG_INFO("\n End of file reached.");
  13490. TxDefaultProfileFileIsNull=TRUE;
  13491. fclose(fptr1);
  13492. }
  13493. else
  13494. {
  13495. TxDefaultProfileFileIsNull=FALSE;
  13496. while(fscanf(fptr1, "%s", word) != EOF)
  13497. {
  13498. if(strcmp(word, "chargingProfileId") == 0)
  13499. {
  13500. n_chargingProfile = n_chargingProfile + 1;
  13501. }
  13502. }
  13503. rewind(fptr1);
  13504. //search Charging Profile Element
  13505. int i = 0;
  13506. int j = 0;
  13507. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13508. {
  13509. #if 0
  13510. //***********connectorId****************/
  13511. c = 0;
  13512. loc = strstr(sLineWord, "connectorId");
  13513. memset(sstr ,0, sizeof(sstr) );
  13514. while (loc[strlen("connectorId")+2+c] != ',')
  13515. {
  13516. sstr[c] = loc[strlen("connectorId")+2+c];
  13517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13518. c++;
  13519. }
  13520. sstr[c] = '\0';
  13521. tempconnectorIdInt = atoi(sstr);
  13522. #endif
  13523. //***********chargingProfileId**************/
  13524. c = 0;
  13525. loc = strstr(sLineWord, "chargingProfileId");
  13526. //DEBUG_INFO("loc=%s\n",loc);
  13527. memset(sstr ,0, sizeof(sstr) );
  13528. if(loc != NULL)
  13529. {
  13530. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13531. {
  13532. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13533. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13534. c++;
  13535. }
  13536. sstr[c] = '\0';
  13537. tempchargingProfileId = atoi(sstr);
  13538. }
  13539. else
  13540. {
  13541. tempchargingProfileId = 0;
  13542. }
  13543. //***********stackLevel**************/
  13544. c = 0;
  13545. loc = strstr(sLineWord, "stackLevel");
  13546. //DEBUG_INFO("loc=%s\n",loc);
  13547. memset(sstr ,0, sizeof(sstr) );
  13548. if(loc != NULL)
  13549. {
  13550. while (loc[2+strlen("stackLevel")+c] != '\"')
  13551. {
  13552. sstr[c] = loc[2+strlen("stackLevel")+c];
  13553. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13554. c++;
  13555. }
  13556. sstr[c] = '\0';
  13557. tempstackLevel = atoi(sstr);
  13558. }
  13559. else
  13560. {
  13561. tempstackLevel = 0;
  13562. }
  13563. //***********chargingProfilePurpose **************/
  13564. c = 0;
  13565. loc = strstr(sLineWord, "chargingProfilePurpose");
  13566. //DEBUG_INFO("loc=%s\n",loc);
  13567. memset(sstr ,0, sizeof(sstr) );
  13568. if(loc != NULL)
  13569. {
  13570. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13571. {
  13572. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13574. c++;
  13575. }
  13576. sstr[c] = '\0';
  13577. strcpy(tempchargingProfilePurposeStr,sstr);
  13578. }
  13579. else
  13580. {
  13581. strcpy(tempchargingProfilePurposeStr,"");
  13582. }
  13583. //***********chargingProfileKind **************/
  13584. c = 0;
  13585. loc = strstr(sLineWord, "chargingProfileKind");
  13586. //DEBUG_INFO("loc=%s\n",loc);
  13587. memset(sstr ,0, sizeof(sstr) );
  13588. if(loc != NULL)
  13589. {
  13590. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13591. {
  13592. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13594. c++;
  13595. }
  13596. sstr[c] = '\0';
  13597. strcpy(tempchargingProfileKindStr,sstr);
  13598. }
  13599. else
  13600. {
  13601. strcpy(tempchargingProfileKindStr,"");
  13602. }
  13603. //***********recurrencyKind **************/
  13604. c = 0;
  13605. loc = strstr(sLineWord, "recurrencyKind");
  13606. //DEBUG_INFO("loc=%s\n",loc);
  13607. memset(sstr ,0, sizeof(sstr) );
  13608. if(loc != NULL)
  13609. {
  13610. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13611. {
  13612. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13613. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13614. c++;
  13615. }
  13616. sstr[c] = '\0';
  13617. strcpy(temprecurrencyKindStr,sstr);
  13618. }
  13619. else
  13620. {
  13621. strcpy(temprecurrencyKindStr,"");
  13622. }
  13623. //***********validFrom**************/
  13624. c = 0;
  13625. loc = strstr(sLineWord, "validFrom");
  13626. if(loc != NULL)
  13627. {
  13628. memset(sstr ,0, sizeof(sstr) );
  13629. while (loc[3+strlen("validFrom")+c] != '\"')
  13630. {
  13631. sstr[c] = loc[3+strlen("validFrom")+c];
  13632. c++;
  13633. }
  13634. sstr[c] = '\0';
  13635. strcpy(tempvalidFromStr,sstr);
  13636. }
  13637. else
  13638. {
  13639. strcpy(tempvalidFromStr,"");
  13640. }
  13641. //***********validTo **************/
  13642. c = 0;
  13643. loc = strstr(sLineWord, "validTo");
  13644. if(loc != NULL)
  13645. {
  13646. memset(sstr ,0, sizeof(sstr) );
  13647. while (loc[3+strlen("validTo")+c] != '\"')
  13648. {
  13649. sstr[c] = loc[3+strlen("validTo")+c];
  13650. c++;
  13651. }
  13652. sstr[c] = '\0';
  13653. strcpy(tempvalidToStr,sstr);
  13654. }
  13655. else
  13656. {
  13657. strcpy(tempvalidToStr,"");
  13658. }
  13659. //***********duration**************/
  13660. c = 0;
  13661. loc = strstr(sLineWord, "duration");
  13662. if(loc != NULL)
  13663. {
  13664. memset(sstr ,0, sizeof(sstr) );
  13665. while (loc[2+strlen("duration")+c] != ',')
  13666. {
  13667. sstr[c] = loc[2+strlen("duration")+c];
  13668. c++;
  13669. }
  13670. sstr[c] = '\0';
  13671. tempdurationInt = atoi(sstr);
  13672. }
  13673. else
  13674. {
  13675. tempdurationInt = 0;
  13676. }
  13677. //**********startSchedule**********/
  13678. c = 0;
  13679. loc = strstr(sLineWord, "startSchedule");
  13680. memset(sstr ,0, sizeof(sstr) );
  13681. while (loc[3+strlen("startSchedule")+c] != '\"')
  13682. {
  13683. sstr[c] = loc[3+strlen("startSchedule")+c];
  13684. c++;
  13685. }
  13686. sstr[c] = '\0';
  13687. strcpy(tempstartScheduleStr, sstr);
  13688. strcpy(TxDefaultProfileScheduleStr, sstr);
  13689. //**********chargingRateUnit**********/
  13690. c = 0;
  13691. loc = strstr(sLineWord, "chargingRateUnit");
  13692. memset(sstr ,0, sizeof(sstr) );
  13693. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13694. {
  13695. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13696. c++;
  13697. }
  13698. sstr[c] = '\0';
  13699. strcpy(tempchargingRateUnitStr, sstr);
  13700. //**********minChargingRate*******/
  13701. c = 0;
  13702. loc = strstr(sLineWord, "minChargingRate");
  13703. if(loc != NULL)
  13704. {
  13705. memset(sstr ,0, sizeof(sstr) );
  13706. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13707. {
  13708. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13709. c++;
  13710. }
  13711. sstr[c] = '\0';
  13712. tempminChargingRateFloat = atof(sstr);
  13713. }
  13714. else
  13715. {
  13716. tempminChargingRateFloat = 0.0;
  13717. }
  13718. //
  13719. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13720. tp.tm_isdst = -1;
  13721. time_t utc = mktime(&tp);
  13722. time_t t = time(NULL);
  13723. diff_t = difftime(t, utc);
  13724. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13725. //parsing strings to words
  13726. i = 0;
  13727. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13728. loc = loc+3+strlen("chargingSchedulePeriod");
  13729. pch = strtok(loc ,"{");
  13730. while (pch != NULL)
  13731. {
  13732. strcpy(SchedulePeriodList[i], pch);
  13733. pch = strtok (NULL, "{");
  13734. i = i + 1;
  13735. }
  13736. n_SchedulePeriods = i;
  13737. for(int i=0;i<n_SchedulePeriods;i++)
  13738. {
  13739. //*************startPeriod****************/
  13740. c = 0;
  13741. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13742. memset(sstr ,0, sizeof(sstr) );
  13743. while (loc[strlen("startPeriod")+2+c] != ',')
  13744. {
  13745. sstr[c] = loc[strlen("startPeriod")+2+c];
  13746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13747. c++;
  13748. }
  13749. sstr[c] = '\0';
  13750. tempStartPeriodInt = atoi(sstr);
  13751. //*************limit****************/
  13752. c = 0;
  13753. loc = strstr(SchedulePeriodList[i], "limit");
  13754. memset(sstr ,0, sizeof(sstr) );
  13755. while (loc[strlen("limit")+2+c] != ',')
  13756. {
  13757. sstr[c] = loc[strlen("limit")+2+c];
  13758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13759. c++;
  13760. }
  13761. sstr[c] = '\0';
  13762. tempLimitInt = atof(sstr);
  13763. //*************numberPhases****************/
  13764. c = 0;
  13765. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13766. memset(sstr ,0, sizeof(sstr) );
  13767. while (loc[strlen("numberPhases")+2+c] != '}')
  13768. {
  13769. sstr[c] = loc[strlen("numberPhases")+2+c];
  13770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13771. c++;
  13772. }
  13773. sstr[c] = '\0';
  13774. tempNumberPhasesInt = atoi(sstr);
  13775. if(j == 0)
  13776. {
  13777. TxDefaultProfile.Duration = tempdurationInt;
  13778. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13779. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13780. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13781. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13782. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13783. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13784. TxDefaultProfile_TEMP.TransactionId = 0;
  13785. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13786. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13787. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13788. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13789. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13790. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13791. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13792. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13793. }
  13794. else
  13795. {
  13796. //other stack level charging Profile
  13797. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13798. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13799. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13800. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13801. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13802. }
  13803. }
  13804. if(MinChargingRate < tempminChargingRateFloat)
  13805. {
  13806. MinChargingRate = tempminChargingRateFloat;
  13807. }
  13808. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13809. if(confirmPeriods < n_SchedulePeriods)
  13810. confirmPeriods = n_SchedulePeriods;
  13811. j = j + 1;
  13812. }
  13813. fclose(fptr1);
  13814. //Stacking Charging Profiles
  13815. for(int l=0; l <(j-1) ;l++)
  13816. {
  13817. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13818. {
  13819. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13820. {
  13821. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13822. {
  13823. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13824. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13825. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13826. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13827. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13828. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13829. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13830. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13831. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13832. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13833. }
  13834. else
  13835. {
  13836. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13837. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13838. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13839. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13840. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13841. }
  13842. }
  13843. }
  13844. }//end of Stacking Charging Profiles
  13845. }// end else
  13846. }// the end of ACCESS TxDefaultProfile
  13847. //****************************TxProfile************************************************/
  13848. #if 0
  13849. switch(gunindex + 1)
  13850. {
  13851. case 0:
  13852. break;
  13853. case 1:
  13854. strcpy(fname, TxProfile_1_JSON );
  13855. break;
  13856. case 2:
  13857. strcpy(fname, TxProfile_2_JSON );
  13858. break;
  13859. default:
  13860. strcpy(fname, TxProfile_1_JSON );
  13861. break;
  13862. }
  13863. #endif
  13864. memset(fname, 0, sizeof fname);
  13865. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13866. TxProfileIsNull=TRUE;
  13867. if((access(fname,F_OK))!=-1)
  13868. {
  13869. fptr1 = fopen(fname, "r");
  13870. c = 0;
  13871. c = fgetc(fptr1);
  13872. //DEBUG_INFO("c:%d\n",c);
  13873. rewind(fptr1);
  13874. if(c == EOF)
  13875. {
  13876. DEBUG_INFO("\n End of file reached.");
  13877. TxProfileIsNull=TRUE;
  13878. fclose(fptr1);
  13879. }
  13880. else
  13881. {
  13882. TxProfileIsNull=FALSE;
  13883. while(fscanf(fptr1, "%s", word) != EOF)
  13884. {
  13885. if(strcmp(word, "chargingProfileId") == 0)
  13886. {
  13887. n_chargingProfile = n_chargingProfile + 1;
  13888. }
  13889. }
  13890. rewind(fptr1);
  13891. //search Charging Profile Element
  13892. int i= 0;
  13893. int j= 0;
  13894. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13895. #if 0
  13896. /***********connectorId****************/
  13897. c = 0;
  13898. loc = strstr(sLineWord, "connectorId");
  13899. memset(sstr ,0, sizeof(sstr) );
  13900. while (loc[strlen("connectorId")+2+c] != ',')
  13901. {
  13902. sstr[c] = loc[strlen("connectorId")+2+c];
  13903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13904. c++;
  13905. }
  13906. sstr[c] = '\0';
  13907. tempconnectorIdInt = atoi(sstr);
  13908. #endif
  13909. //***********chargingProfileId**************/
  13910. c = 0;
  13911. loc = strstr(sLineWord, "chargingProfileId");
  13912. memset(sstr ,0, sizeof(sstr) );
  13913. if(loc != NULL)
  13914. {
  13915. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13916. {
  13917. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13918. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13919. c++;
  13920. }
  13921. sstr[c] = '\0';
  13922. tempchargingProfileId = atoi(sstr);
  13923. }
  13924. else
  13925. {
  13926. tempchargingProfileId = 0;
  13927. }
  13928. //***********transactionId **************/
  13929. c = 0;
  13930. loc = strstr(sLineWord, "transactionId");
  13931. //DEBUG_INFO("loc=%s\n",loc);
  13932. memset(sstr ,0, sizeof(sstr) );
  13933. if(loc != NULL)
  13934. {
  13935. while (loc[2+strlen("transactionId")+c] != '\"')
  13936. {
  13937. sstr[c] = loc[2+strlen("transactionId")+c];
  13938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13939. c++;
  13940. }
  13941. sstr[c] = '\0';
  13942. temptransactionId = atoi(sstr);
  13943. }
  13944. else
  13945. {
  13946. temptransactionId = 0;
  13947. }
  13948. //***********stackLevel**************/
  13949. c = 0;
  13950. loc = strstr(sLineWord, "stackLevel");
  13951. //DEBUG_INFO("loc=%s\n",loc);
  13952. memset(sstr ,0, sizeof(sstr) );
  13953. if(loc != NULL)
  13954. {
  13955. while (loc[2+strlen("stackLevel")+c] != '\"')
  13956. {
  13957. sstr[c] = loc[2+strlen("stackLevel")+c];
  13958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13959. c++;
  13960. }
  13961. sstr[c] = '\0';
  13962. tempstackLevel = atoi(sstr);
  13963. }
  13964. else
  13965. {
  13966. tempstackLevel = 0;
  13967. }
  13968. //***********chargingProfilePurpose **************/
  13969. c = 0;
  13970. loc = strstr(sLineWord, "chargingProfilePurpose");
  13971. //DEBUG_INFO("loc=%s\n",loc);
  13972. memset(sstr ,0, sizeof(sstr) );
  13973. if(loc != NULL)
  13974. {
  13975. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13976. {
  13977. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13979. c++;
  13980. }
  13981. sstr[c] = '\0';
  13982. strcpy(tempchargingProfilePurposeStr,sstr);
  13983. }
  13984. else
  13985. {
  13986. strcpy(tempchargingProfilePurposeStr,"");
  13987. }
  13988. //***********chargingProfileKind **************/
  13989. c = 0;
  13990. loc = strstr(sLineWord, "chargingProfileKind");
  13991. //DEBUG_INFO("loc=%s\n",loc);
  13992. memset(sstr ,0, sizeof(sstr) );
  13993. if(loc != NULL)
  13994. {
  13995. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13996. {
  13997. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13998. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13999. c++;
  14000. }
  14001. sstr[c] = '\0';
  14002. strcpy(tempchargingProfileKindStr,sstr);
  14003. }
  14004. else
  14005. {
  14006. strcpy(tempchargingProfileKindStr,"");
  14007. }
  14008. //***********recurrencyKind **************/
  14009. c = 0;
  14010. loc = strstr(sLineWord, "recurrencyKind");
  14011. //DEBUG_INFO("loc=%s\n",loc);
  14012. memset(sstr ,0, sizeof(sstr) );
  14013. if(loc != NULL)
  14014. {
  14015. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14016. {
  14017. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14019. c++;
  14020. }
  14021. sstr[c] = '\0';
  14022. strcpy(temprecurrencyKindStr,sstr);
  14023. }
  14024. else
  14025. {
  14026. strcpy(temprecurrencyKindStr,"");
  14027. }
  14028. //***********validFrom**************/
  14029. c = 0;
  14030. loc = strstr(sLineWord, "validFrom");
  14031. if(loc != NULL)
  14032. {
  14033. memset(sstr ,0, sizeof(sstr) );
  14034. while (loc[3+strlen("validFrom")+c] != '\"')
  14035. {
  14036. sstr[c] = loc[3+strlen("validFrom")+c];
  14037. c++;
  14038. }
  14039. sstr[c] = '\0';
  14040. strcpy(tempvalidFromStr,sstr);
  14041. }
  14042. else
  14043. {
  14044. strcpy(tempvalidFromStr,"");
  14045. }
  14046. //***********validTo**************/
  14047. c = 0;
  14048. loc = strstr(sLineWord, "validTo");
  14049. if(loc != NULL)
  14050. {
  14051. memset(sstr ,0, sizeof(sstr) );
  14052. while (loc[3+strlen("validTo")+c] != '\"')
  14053. {
  14054. sstr[c] = loc[3+strlen("validTo")+c];
  14055. c++;
  14056. }
  14057. sstr[c] = '\0';
  14058. strcpy(tempvalidToStr,sstr);
  14059. }
  14060. else
  14061. {
  14062. strcpy(tempvalidToStr,"");
  14063. }
  14064. //***********duration**************/
  14065. c = 0;
  14066. loc = strstr(sLineWord, "duration");
  14067. //DEBUG_INFO("loc=%s\n",loc);
  14068. memset(sstr ,0, sizeof(sstr) );
  14069. if(loc != NULL)
  14070. {
  14071. while (loc[2+strlen("duration")+c] != '\"')
  14072. {
  14073. sstr[c] = loc[2+strlen("duration")+c];
  14074. c++;
  14075. }
  14076. sstr[c] = '\0';
  14077. tempdurationInt = atoi(sstr);
  14078. }
  14079. else
  14080. {
  14081. tempdurationInt = 0;
  14082. }
  14083. //**********startSchedule**********/
  14084. c = 0;
  14085. loc = strstr(sLineWord, "startSchedule");
  14086. memset(sstr ,0, sizeof(sstr) );
  14087. while (loc[3+strlen("startSchedule")+c] != '\"')
  14088. {
  14089. sstr[c] = loc[3+strlen("startSchedule")+c];
  14090. c++;
  14091. }
  14092. sstr[c] = '\0';
  14093. strcpy(tempstartScheduleStr, sstr);
  14094. strcpy(TxProfileScheduleStr, sstr);
  14095. //**********chargingRateUnit**********/
  14096. c = 0;
  14097. loc = strstr(sLineWord, "chargingRateUnit");
  14098. memset(sstr ,0, sizeof(sstr) );
  14099. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14100. {
  14101. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14102. c++;
  14103. }
  14104. sstr[c] = '\0';
  14105. strcpy(tempchargingRateUnitStr, sstr);
  14106. //**********minChargingRate*******/
  14107. c = 0;
  14108. loc = strstr(sLineWord, "minChargingRate");
  14109. if(loc != NULL)
  14110. {
  14111. memset(sstr ,0, sizeof(sstr) );
  14112. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14113. {
  14114. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14115. c++;
  14116. }
  14117. sstr[c] = '\0';
  14118. tempminChargingRateFloat = atof(sstr);
  14119. }
  14120. else
  14121. {
  14122. tempminChargingRateFloat = 0.0;
  14123. }
  14124. //
  14125. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14126. tp.tm_isdst = -1;
  14127. time_t utc = mktime(&tp);
  14128. time_t t = time(NULL);
  14129. diff_t = difftime(t, utc);
  14130. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14131. //parsing strings to words
  14132. i = 0;
  14133. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14134. loc = loc+3+strlen("chargingSchedulePeriod");
  14135. pch = strtok(loc ,"{");
  14136. while (pch != NULL)
  14137. {
  14138. strcpy(SchedulePeriodList[i], pch);
  14139. pch = strtok (NULL, "{");
  14140. i = i + 1;
  14141. }
  14142. n_SchedulePeriods = i;
  14143. for(int i=0;i<n_SchedulePeriods;i++)
  14144. {
  14145. //*************startPeriod****************/
  14146. c = 0;
  14147. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14148. memset(sstr ,0, sizeof(sstr) );
  14149. while (loc[strlen("startPeriod")+2+c] != ',')
  14150. {
  14151. sstr[c] = loc[strlen("startPeriod")+2+c];
  14152. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14153. c++;
  14154. }
  14155. sstr[c] = '\0';
  14156. tempStartPeriodInt = atoi(sstr);
  14157. //*************limit****************/
  14158. c = 0;
  14159. loc = strstr(SchedulePeriodList[i], "limit");
  14160. memset(sstr ,0, sizeof(sstr) );
  14161. while (loc[strlen("limit")+2+c] != ',')
  14162. {
  14163. sstr[c] = loc[strlen("limit")+2+c];
  14164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14165. c++;
  14166. }
  14167. sstr[c] = '\0';
  14168. tempLimitInt = atof(sstr);
  14169. //*************numberPhases****************/
  14170. c = 0;
  14171. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14172. memset(sstr ,0, sizeof(sstr) );
  14173. while (loc[strlen("numberPhases")+2+c] != '}')
  14174. {
  14175. sstr[c] = loc[strlen("numberPhases")+2+c];
  14176. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14177. c++;
  14178. }
  14179. sstr[c] = '\0';
  14180. tempNumberPhasesInt = atoi(sstr);
  14181. //TxProfile.Duration = durationInt;
  14182. TxProfile.TotalPeriod = n_SchedulePeriods;
  14183. TxProfile.Period[i].Limit = tempLimitInt;
  14184. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14185. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14186. }
  14187. if(MinChargingRate < tempminChargingRateFloat)
  14188. {
  14189. MinChargingRate = tempminChargingRateFloat;
  14190. }
  14191. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14192. if(confirmPeriods < n_SchedulePeriods)
  14193. confirmPeriods = n_SchedulePeriods;
  14194. if(j == 0)
  14195. {
  14196. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14197. TxProfile_TEMP.StackLevel = tempstackLevel;
  14198. TxProfile_TEMP.TransactionId = 0;
  14199. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14200. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14201. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14202. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14203. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14204. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14205. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14206. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14207. }
  14208. }
  14209. fclose(fptr1);
  14210. }
  14211. }// the end of ACCESS TxProfile
  14212. //-----------------------------------------------CompositeSchedule--------------------------//
  14213. int period=0;
  14214. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14215. {
  14216. //TxProfile
  14217. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14218. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14219. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14220. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14221. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14222. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14223. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14224. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14225. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14226. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14227. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14228. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14229. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14230. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14231. {
  14232. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14233. {
  14234. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14237. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14238. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14239. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14240. period = period + 1;
  14241. }
  14242. else
  14243. {
  14244. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14245. {
  14246. }
  14247. else
  14248. {
  14249. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14252. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14253. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14254. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14255. period = period + 1;
  14256. }
  14257. }
  14258. }
  14259. struct tm tp;
  14260. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14261. tp.tm_isdst = -1;
  14262. time_t utc = mktime(&tp);
  14263. time_t t = time(NULL);
  14264. double diff_f = difftime(t, utc);
  14265. int diff_i;// = (int)diff_f;
  14266. int quotient; // = diff_i / 86400;//86400 seconds/day
  14267. if(diff_f >= 0)
  14268. {
  14269. diff_i = (int)diff_f;
  14270. quotient = diff_i / 86400;//86400 seconds/day
  14271. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14272. {
  14273. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14274. {
  14275. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14276. {
  14277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14278. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14279. }
  14280. else
  14281. {
  14282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14283. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14284. }
  14285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14287. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14288. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14289. period = period + 1;
  14290. }
  14291. }
  14292. }// end of if(diff_f >= 0)
  14293. }
  14294. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14295. {
  14296. //TxDefaultProfile
  14297. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14298. struct tm tp;
  14299. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14300. tp.tm_isdst = -1;
  14301. time_t utc = mktime(&tp);
  14302. time_t t = time(NULL);
  14303. double diff_f = difftime(t, utc);
  14304. int diff_i;// = (int)diff_f;
  14305. int quotient; // = diff_i / 86400;//86400 seconds/day
  14306. int remainder;
  14307. //---- Define StartSchedule----/
  14308. struct tm *gtime;
  14309. time_t now;
  14310. char buf[28];
  14311. //---Read the current system time---/
  14312. time(&now);
  14313. //---Convert the system time to GMT (now UTC)---/
  14314. gtime = gmtime(&now);
  14315. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14316. if(diff_f >= 0)
  14317. {
  14318. diff_i = (int)diff_f;
  14319. quotient = diff_i / 86400;//86400 seconds/day
  14320. remainder = diff_i % 86400;
  14321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14322. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14323. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14324. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14325. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14326. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14327. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14328. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14329. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14330. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14331. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14332. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14333. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14334. {
  14335. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14336. {
  14337. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14338. {
  14339. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14340. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14342. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14343. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14344. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14345. period = period + 1;
  14346. }
  14347. else
  14348. {
  14349. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14351. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14352. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14353. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14354. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14355. period = period + 1;
  14356. }
  14357. }
  14358. }
  14359. } // end of diff_f >= 0
  14360. }
  14361. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14362. {
  14363. //TxDefaultProfile
  14364. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14365. struct tm tp;
  14366. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14367. tp.tm_isdst = -1;
  14368. time_t utc = mktime(&tp);
  14369. time_t t = time(NULL);
  14370. double diff_f = difftime(t, utc);
  14371. int diff_i;// = (int)diff_f;
  14372. int quotient; // = diff_i / 86400;//86400 seconds/day
  14373. int remainder;
  14374. //---- Define StartSchedule----/
  14375. struct tm *gtime;
  14376. time_t now;
  14377. char buf[28];
  14378. //---Read the current system time---/
  14379. time(&now);
  14380. //---Convert the system time to GMT (now UTC)---/
  14381. gtime = gmtime(&now);
  14382. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14383. if(diff_f >= 0)
  14384. {
  14385. diff_i = (int)diff_f;
  14386. quotient = diff_i / 86400;//86400 seconds/day
  14387. remainder = diff_i % 86400;
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14393. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14394. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14395. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14396. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14397. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14400. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14401. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14402. {
  14403. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14404. {
  14405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14408. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14409. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14410. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14411. period = period + 1;
  14412. }
  14413. }
  14414. } //end of diff_f >= 0
  14415. }
  14416. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14417. {
  14418. //ChargePointMaxProfile
  14419. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14420. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14421. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14422. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14423. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14425. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14426. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14427. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14428. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14429. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14430. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14431. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14432. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14433. {
  14434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14437. period = period + 1;
  14438. }
  14439. }
  14440. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14441. {
  14442. //TxProfile Daily
  14443. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14445. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14446. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14447. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14449. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14450. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14451. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14452. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14453. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14454. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14455. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14456. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14457. {
  14458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14459. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14461. }
  14462. }
  14463. confirmPeriods = period;
  14464. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14465. DEBUG_INFO("\nchargingProfileId =%d, transactionId =%d\n, stackLevel =%d, chargingProfilePurpose=%s, chargingProfileKind=%s, recurrencyKind =%s, validFrom =%s, validTo =%s, duration=%d , startSchedule =%s, chargingRateUnit=%s, minChargingRate=%f,"
  14466. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14467. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14468. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14469. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14470. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14471. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14472. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14473. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14474. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14475. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14476. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14477. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14478. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14481. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14482. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14483. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14495. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14497. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14498. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14499. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14500. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14502. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14503. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14504. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14505. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14506. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14507. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14508. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14509. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14510. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14511. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14512. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14513. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14514. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14515. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14516. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14517. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14518. }
  14519. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14520. {
  14521. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14522. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14523. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14524. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14525. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14526. }
  14527. int GetWebSocketPingInterval(void)
  14528. {
  14529. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14530. }
  14531. int GetInternetConn(void)
  14532. {
  14533. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14534. }
  14535. void LWS_Send(char * str)
  14536. {
  14537. //=====================================================
  14538. // Check InternetConn 0: disconnected, 1: connected
  14539. //====================================================
  14540. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14541. {
  14542. DEBUG_INFO("\n offline now !!!\n");
  14543. return;
  14544. }
  14545. pthread_mutex_lock(&lock);
  14546. memset(SendBuffer,0,SendBufLen);
  14547. sprintf((char *)SendBuffer, "%s", str);
  14548. pthread_mutex_unlock(&lock);
  14549. lws_callback_on_writable(wsi_client);
  14550. lws_service(context, 10000);//timeout_ms
  14551. }