MessageHandler.c 613 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000
  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] != ',')&&(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. if(loc != NULL)
  4605. {
  4606. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4607. {
  4608. sstr[c] = loc[strlen("numberPhases")+2+c];
  4609. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4610. c++;
  4611. }
  4612. sstr[c] = '\0';
  4613. tempNumberPhasesInt = atoi(sstr);
  4614. }
  4615. else
  4616. {
  4617. tempNumberPhasesInt = 0;
  4618. }
  4619. ChargePointMaxProfile.Duration = durationInt;
  4620. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4621. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4622. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4623. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4624. }
  4625. if(MinChargingRate < tempminChargingRateFloat)
  4626. MinChargingRate = tempminChargingRateFloat;
  4627. }
  4628. }// End of file ChargingProfile
  4629. } //THE END OF ACCESS ChargePointMaxProfile
  4630. //******************************TxDefaultProfile***********************************************/
  4631. strcpy(fname, TxDefaultProfile_0_JSON);
  4632. memset(word, 0, 30);
  4633. memset(sLineWord, 0, 1060);
  4634. //char word[30]={0};
  4635. //char sLineWord[1060]={0};
  4636. n_chargingProfile=0;
  4637. TxDefaultProfileFileIsNull=TRUE;
  4638. if((access(fname,F_OK))!=-1)
  4639. {
  4640. fptr1 = fopen(fname, "r");
  4641. c = 0;
  4642. c = fgetc(fptr1);
  4643. //DEBUG_INFO("c:%d\n",c);
  4644. rewind(fptr1);
  4645. if(c == EOF)
  4646. {
  4647. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4648. TxDefaultProfileFileIsNull=TRUE;
  4649. fclose(fptr1);
  4650. }
  4651. else
  4652. {
  4653. TxDefaultProfileFileIsNull=FALSE;
  4654. while(fscanf(fptr1, "%s", word) != EOF)
  4655. {
  4656. if(strcmp(word, "chargingProfileId") == 0)
  4657. {
  4658. n_chargingProfile = n_chargingProfile + 1;
  4659. printf("Found\n");
  4660. }
  4661. }
  4662. rewind(fptr1);
  4663. //search Charging Profile Element
  4664. int i= 0;
  4665. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4666. #if 0
  4667. /***********connectorId****************/
  4668. c = 0;
  4669. loc = strstr(sLineWord, "connectorId");
  4670. // printf("loc=%s\n",loc);
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[strlen("connectorId")+2+c] != ',')
  4673. {
  4674. sstr[c] = loc[strlen("connectorId")+2+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4680. tempconnectorIdInt = atoi(sstr);
  4681. #endif
  4682. //***********validFrom**************/
  4683. c = 0;
  4684. loc = strstr(sLineWord, "validFrom");
  4685. //DEBUG_INFO("loc=%s\n",loc);
  4686. memset(sstr ,0, sizeof(sstr) );
  4687. if(loc != NULL)
  4688. {
  4689. while (loc[3+strlen("validFrom")+c] != '\"')
  4690. {
  4691. sstr[c] = loc[3+strlen("validFrom")+c];
  4692. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4693. c++;
  4694. }
  4695. sstr[c] = '\0';
  4696. DEBUG_INFO("validFrom=%s\n",sstr);
  4697. strcpy(tempvalidFromStr,sstr);
  4698. }
  4699. else
  4700. {
  4701. strcpy(tempvalidFromStr,"");
  4702. }
  4703. //**********startSchedule**********/
  4704. c = 0;
  4705. loc = strstr(sLineWord, "startSchedule");
  4706. //DEBUG_INFO("loc=%s\n",loc);
  4707. memset(sstr ,0, sizeof(sstr) );
  4708. while (loc[3+strlen("startSchedule")+c] != '\"')
  4709. {
  4710. sstr[c] = loc[3+strlen("startSchedule")+c];
  4711. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4712. c++;
  4713. }
  4714. sstr[c] = '\0';
  4715. strcpy(tempstartScheduleStr, sstr);
  4716. strcpy(TxDefaultProfileScheduleStr, sstr);
  4717. //**********chargingRateUnit**********/
  4718. c = 0;
  4719. loc = strstr(sLineWord, "chargingRateUnit");
  4720. memset(sstr ,0, sizeof(sstr) );
  4721. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4722. {
  4723. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4724. c++;
  4725. }
  4726. sstr[c] = '\0';
  4727. strcpy(tempchargingRateUnitStr, sstr);
  4728. //**********minChargingRate*******/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "minChargingRate");
  4731. //printf("loc=%s\n",loc);
  4732. if(loc != NULL)
  4733. {
  4734. memset(sstr ,0, sizeof(sstr) );
  4735. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4736. {
  4737. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4739. c++;
  4740. }
  4741. sstr[c] = '\0';
  4742. tempminChargingRateFloat = atof(sstr);
  4743. }
  4744. else
  4745. {
  4746. tempminChargingRateFloat = 0.0;
  4747. }
  4748. #if 0
  4749. //
  4750. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4751. tp.tm_isdst = -1;
  4752. time_t utc = mktime(&tp);
  4753. // current time
  4754. time_t t = time(NULL);
  4755. //diff_t = difftime(t, utc);
  4756. #endif
  4757. //parsing strings to words
  4758. i = 0;
  4759. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4760. loc = loc+3+strlen("chargingSchedulePeriod");
  4761. pch = strtok(loc ,"{");
  4762. while (pch != NULL)
  4763. {
  4764. strcpy(SchedulePeriodList[i], pch);
  4765. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4766. //printf ("%s\n",pch);
  4767. pch = strtok (NULL, "{");
  4768. i = i + 1;
  4769. }
  4770. n_SchedulePeriods = i;
  4771. for(int i=0;i<n_SchedulePeriods;i++)
  4772. {
  4773. //*************startPeriod****************/
  4774. c = 0;
  4775. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4776. memset(sstr ,0, sizeof(sstr) );
  4777. while (loc[strlen("startPeriod")+2+c] != ',')
  4778. {
  4779. sstr[c] = loc[strlen("startPeriod")+2+c];
  4780. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4781. c++;
  4782. }
  4783. sstr[c] = '\0';
  4784. tempStartPeriodInt = atoi(sstr);
  4785. //*************limit****************/
  4786. c = 0;
  4787. loc = strstr(SchedulePeriodList[i], "limit");
  4788. memset(sstr ,0, sizeof(sstr) );
  4789. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4790. {
  4791. sstr[c] = loc[strlen("limit")+2+c];
  4792. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4793. c++;
  4794. }
  4795. sstr[c] = '\0';
  4796. tempLimitInt = atof(sstr);
  4797. //*************numberPhases****************/
  4798. c = 0;
  4799. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4800. memset(sstr ,0, sizeof(sstr) );
  4801. if(loc != NULL)
  4802. {
  4803. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4804. {
  4805. sstr[c] = loc[strlen("numberPhases")+2+c];
  4806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4807. c++;
  4808. }
  4809. sstr[c] = '\0';
  4810. tempNumberPhasesInt = atoi(sstr);
  4811. }
  4812. else
  4813. {
  4814. tempNumberPhasesInt = 0;
  4815. }
  4816. TxDefaultProfile.Duration = durationInt;
  4817. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4818. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4819. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4820. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4821. }
  4822. if(MinChargingRate < tempminChargingRateFloat)
  4823. MinChargingRate = tempminChargingRateFloat;
  4824. }
  4825. }
  4826. }// the end of ACCESS TxDefaultProfile
  4827. //--------------------- Composite Schedule-----------------------------//
  4828. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4829. {
  4830. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4831. struct tm tp;
  4832. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4833. tp.tm_isdst = -1;
  4834. time_t utc = mktime(&tp);
  4835. time_t t = time(NULL);
  4836. double diff_f = difftime(t, utc);
  4837. int diff_i; //= (int)diff_f;
  4838. int quotient; //= diff_i / 86400;//86400 seconds/day
  4839. int period = 0;
  4840. if(diff_f >= 0)
  4841. {
  4842. diff_i = (int)diff_f;
  4843. quotient = diff_i / 86400;
  4844. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4845. {
  4846. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4847. {
  4848. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4849. {
  4850. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4851. }
  4852. else
  4853. {
  4854. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4855. }
  4856. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4857. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4858. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4859. period = period + 1;
  4860. }
  4861. }
  4862. }
  4863. confirmPeriods = period;
  4864. }
  4865. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4866. {
  4867. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4868. struct tm tp;
  4869. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4870. tp.tm_isdst = -1;
  4871. time_t utc = mktime(&tp);
  4872. time_t t = time(NULL);
  4873. double diff_f = difftime(t, utc);
  4874. int diff_i; // = (int)diff_f;
  4875. int quotient; // = diff_i / 86400;//86400 seconds/day
  4876. int period = 0;
  4877. if(diff_f >= 0)
  4878. {
  4879. diff_i = (int)diff_f;
  4880. quotient = diff_i / 86400;//86400 seconds/day
  4881. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4882. {
  4883. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4884. {
  4885. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4886. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4887. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4888. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4889. period = period + 1;
  4890. }
  4891. }
  4892. }
  4893. confirmPeriods = period;
  4894. }
  4895. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4896. {
  4897. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4898. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4899. {
  4900. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4901. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4902. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4903. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4904. }
  4905. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4906. }
  4907. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4908. {
  4909. confirmPeriods = 0;
  4910. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4911. goto end;
  4912. }
  4913. //* Define temporary variables */
  4914. struct tm *gtime;
  4915. time_t now;
  4916. char buf[28];
  4917. /* Read the current system time */
  4918. time(&now);
  4919. /* Convert the system time to GMT (now UTC) */
  4920. gtime = gmtime(&now);
  4921. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4922. // make .conf
  4923. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4924. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4925. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4926. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4927. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4928. }
  4929. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4930. {
  4931. //*****************************ChargePointMaxProfile******************************************/
  4932. strcpy(fname, ChargePointMaxProfile_JSON);
  4933. ChargePointMaxProfileIsNull=TRUE;
  4934. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4935. {
  4936. fptr1 = fopen(fname, "r");
  4937. int c;
  4938. c = fgetc(fptr1);
  4939. //DEBUG_INFO("c:%d\n",c);
  4940. rewind(fptr1);
  4941. if(c == EOF)
  4942. {
  4943. DEBUG_INFO("\n End of file reached.");
  4944. ChargePointMaxProfileIsNull=TRUE;
  4945. fclose(fptr1);
  4946. }
  4947. else
  4948. {
  4949. ChargePointMaxProfileIsNull=FALSE;
  4950. while(fscanf(fptr1, "%s", word) != EOF)
  4951. {
  4952. if(strcmp(word, "chargingProfileId") == 0)
  4953. {
  4954. n_chargingProfile = n_chargingProfile + 1;
  4955. }
  4956. }
  4957. rewind(fptr1);
  4958. //search Charging Profile Element
  4959. int i = 0;
  4960. int j = 0;
  4961. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4962. #if 0
  4963. /***********connectorId****************/
  4964. c = 0;
  4965. loc = strstr(sLineWord, "connectorId");
  4966. memset(sstr ,0, sizeof(sstr) );
  4967. while (loc[strlen("connectorId")+2+c] != ',')
  4968. {
  4969. sstr[c] = loc[strlen("connectorId")+2+c];
  4970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4971. c++;
  4972. }
  4973. sstr[c] = '\0';
  4974. tempconnectorIdInt = atoi(sstr);
  4975. #endif
  4976. //***********validFrom**************/
  4977. c = 0;
  4978. loc = strstr(sLineWord, "validFrom");
  4979. if(loc != NULL)
  4980. {
  4981. memset(sstr ,0, sizeof(sstr) );
  4982. while (loc[3+strlen("validFrom")+c] != '\"')
  4983. {
  4984. sstr[c] = loc[3+strlen("validFrom")+c];
  4985. c++;
  4986. }
  4987. sstr[c] = '\0';
  4988. strcpy(tempvalidFromStr,sstr);
  4989. }
  4990. else
  4991. {
  4992. strcpy(tempvalidFromStr,"");
  4993. }
  4994. //***********validFrom**************/
  4995. c = 0;
  4996. loc = strstr(sLineWord, "duration");
  4997. if(loc != NULL)
  4998. {
  4999. memset(sstr ,0, sizeof(sstr) );
  5000. while (loc[2+strlen("duration")+c] != ',')
  5001. {
  5002. sstr[c] = loc[2+strlen("duration")+c];
  5003. c++;
  5004. }
  5005. sstr[c] = '\0';
  5006. tempdurationInt = atoi(sstr);
  5007. }
  5008. else
  5009. {
  5010. tempdurationInt = 0;
  5011. }
  5012. //**********startSchedule**********/
  5013. c = 0;
  5014. loc = strstr(sLineWord, "startSchedule");
  5015. memset(sstr ,0, sizeof(sstr) );
  5016. while (loc[3+strlen("startSchedule")+c] != '\"')
  5017. {
  5018. sstr[c] = loc[3+strlen("startSchedule")+c];
  5019. c++;
  5020. }
  5021. sstr[c] = '\0';
  5022. strcpy(tempstartScheduleStr, sstr);
  5023. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5024. //**********chargingRateUnit**********/
  5025. c = 0;
  5026. loc = strstr(sLineWord, "chargingRateUnit");
  5027. memset(sstr ,0, sizeof(sstr) );
  5028. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5029. {
  5030. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5031. c++;
  5032. }
  5033. sstr[c] = '\0';
  5034. strcpy(tempchargingRateUnitStr, sstr);
  5035. //**********minChargingRate*******/
  5036. c = 0;
  5037. loc = strstr(sLineWord, "minChargingRate");
  5038. if(loc != NULL)
  5039. {
  5040. memset(sstr ,0, sizeof(sstr) );
  5041. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5042. {
  5043. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5044. c++;
  5045. }
  5046. sstr[c] = '\0';
  5047. tempminChargingRateFloat = atof(sstr);
  5048. }
  5049. else
  5050. {
  5051. tempminChargingRateFloat = 0.0;
  5052. }
  5053. #if 0
  5054. //
  5055. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5056. tp.tm_isdst = -1;
  5057. time_t utc = mktime(&tp);
  5058. time_t t = time(NULL);
  5059. //diff_t = difftime(t, utc);
  5060. #endif
  5061. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5062. //DEBUG_INFO(" debug 5 -1\n");
  5063. //parsing strings to words
  5064. i = 0;
  5065. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5066. loc = loc+3+strlen("chargingSchedulePeriod");
  5067. pch = strtok(loc ,"{");
  5068. while (pch != NULL)
  5069. {
  5070. strcpy(SchedulePeriodList[i], pch);
  5071. pch = strtok (NULL, "{");
  5072. i = i + 1;
  5073. }
  5074. n_SchedulePeriods = i;
  5075. for(int i=0;i<n_SchedulePeriods;i++)
  5076. {
  5077. //*************startPeriod****************/
  5078. c = 0;
  5079. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5080. memset(sstr ,0, sizeof(sstr) );
  5081. while (loc[strlen("startPeriod")+2+c] != ',')
  5082. {
  5083. sstr[c] = loc[strlen("startPeriod")+2+c];
  5084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5085. c++;
  5086. }
  5087. sstr[c] = '\0';
  5088. tempStartPeriodInt = atoi(sstr);
  5089. //*************limit****************/
  5090. c = 0;
  5091. loc = strstr(SchedulePeriodList[i], "limit");
  5092. memset(sstr ,0, sizeof(sstr) );
  5093. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5094. {
  5095. sstr[c] = loc[strlen("limit")+2+c];
  5096. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5097. c++;
  5098. }
  5099. sstr[c] = '\0';
  5100. tempLimitInt = atof(sstr);
  5101. //*************numberPhases****************/
  5102. c = 0;
  5103. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5104. memset(sstr ,0, sizeof(sstr) );
  5105. if(loc != NULL)
  5106. {
  5107. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5108. {
  5109. sstr[c] = loc[strlen("numberPhases")+2+c];
  5110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5111. c++;
  5112. }
  5113. sstr[c] = '\0';
  5114. tempNumberPhasesInt = atoi(sstr);
  5115. }
  5116. else
  5117. {
  5118. tempNumberPhasesInt = 0;
  5119. }
  5120. if(j == 0)
  5121. {
  5122. ChargePointMaxProfile.Duration = tempdurationInt;
  5123. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5124. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5125. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5126. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5127. }
  5128. }
  5129. if(MinChargingRate < tempminChargingRateFloat)
  5130. {
  5131. MinChargingRate = tempminChargingRateFloat;
  5132. }
  5133. if(confirmPeriods < n_SchedulePeriods)
  5134. {
  5135. confirmPeriods = n_SchedulePeriods;
  5136. }
  5137. j = j + 1;
  5138. }
  5139. fclose(fptr1);
  5140. }
  5141. }// the end of access file ChargePointMaxProfile
  5142. //****************************TxDefaultProfile************************************************/
  5143. memset(fname, 0, sizeof fname);
  5144. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5145. TxDefaultProfileFileIsNull=TRUE;
  5146. if((access(fname,F_OK))!=-1)
  5147. {
  5148. fptr1 = fopen(fname, "r");
  5149. c = 0;
  5150. c = fgetc(fptr1);
  5151. //DEBUG_INFO("c:%d\n",c);
  5152. rewind(fptr1);
  5153. if(c == EOF)
  5154. {
  5155. DEBUG_INFO("\n End of file reached.");
  5156. TxDefaultProfileFileIsNull=TRUE;
  5157. fclose(fptr1);
  5158. }
  5159. else
  5160. {
  5161. TxDefaultProfileFileIsNull=FALSE;
  5162. while(fscanf(fptr1, "%s", word) != EOF)
  5163. {
  5164. if(strcmp(word, "chargingProfileId") == 0)
  5165. {
  5166. n_chargingProfile = n_chargingProfile + 1;
  5167. }
  5168. }
  5169. rewind(fptr1);
  5170. //search Charging Profile Element
  5171. int i = 0;
  5172. int j = 0;
  5173. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5174. //DEBUG_INFO(" 1-1\n");
  5175. #if 0
  5176. /***********connectorId****************/
  5177. c = 0;
  5178. loc = strstr(sLineWord, "connectorId");
  5179. memset(sstr ,0, sizeof(sstr) );
  5180. while (loc[strlen("connectorId")+2+c] != ',')
  5181. {
  5182. sstr[c] = loc[strlen("connectorId")+2+c];
  5183. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5184. c++;
  5185. }
  5186. sstr[c] = '\0';
  5187. tempconnectorIdInt = atoi(sstr);
  5188. #endif
  5189. //***********validFrom**************/
  5190. c = 0;
  5191. loc = strstr(sLineWord, "validFrom");
  5192. if(loc != NULL)
  5193. {
  5194. memset(sstr ,0, sizeof(sstr) );
  5195. while (loc[3+strlen("validFrom")+c] != '\"')
  5196. {
  5197. sstr[c] = loc[3+strlen("validFrom")+c];
  5198. c++;
  5199. }
  5200. sstr[c] = '\0';
  5201. strcpy(tempvalidFromStr,sstr);
  5202. }
  5203. else
  5204. {
  5205. strcpy(tempvalidFromStr,"");
  5206. }
  5207. //***********validFrom**************/
  5208. c = 0;
  5209. loc = strstr(sLineWord, "duration");
  5210. if(loc != NULL)
  5211. {
  5212. memset(sstr ,0, sizeof(sstr) );
  5213. while (loc[2+strlen("duration")+c] != ',')
  5214. {
  5215. sstr[c] = loc[2+strlen("duration")+c];
  5216. c++;
  5217. }
  5218. sstr[c] = '\0';
  5219. tempdurationInt = atoi(sstr);
  5220. }
  5221. else
  5222. {
  5223. tempdurationInt = 0;
  5224. }
  5225. //**********startSchedule**********/
  5226. c = 0;
  5227. loc = strstr(sLineWord, "startSchedule");
  5228. memset(sstr ,0, sizeof(sstr) );
  5229. while (loc[3+strlen("startSchedule")+c] != '\"')
  5230. {
  5231. sstr[c] = loc[3+strlen("startSchedule")+c];
  5232. c++;
  5233. }
  5234. sstr[c] = '\0';
  5235. strcpy(tempstartScheduleStr, sstr);
  5236. strcpy(TxDefaultProfileScheduleStr, sstr);
  5237. //**********chargingRateUnit**********/
  5238. c = 0;
  5239. loc = strstr(sLineWord, "chargingRateUnit");
  5240. memset(sstr ,0, sizeof(sstr) );
  5241. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5242. {
  5243. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5244. c++;
  5245. }
  5246. sstr[c] = '\0';
  5247. strcpy(tempchargingRateUnitStr, sstr);
  5248. //**********minChargingRate*******/
  5249. c = 0;
  5250. loc = strstr(sLineWord, "minChargingRate");
  5251. if(loc != NULL)
  5252. {
  5253. memset(sstr ,0, sizeof(sstr) );
  5254. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5255. {
  5256. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5257. c++;
  5258. }
  5259. sstr[c] = '\0';
  5260. tempminChargingRateFloat = atof(sstr);
  5261. }
  5262. else
  5263. {
  5264. tempminChargingRateFloat = 0.0;
  5265. }
  5266. #if 0
  5267. //
  5268. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5269. tp.tm_isdst = -1;
  5270. time_t utc = mktime(&tp);
  5271. time_t t = time(NULL);
  5272. //diff_t = difftime(t, utc);
  5273. #endif
  5274. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5275. //parsing strings to words
  5276. i = 0;
  5277. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5278. loc = loc+3+strlen("chargingSchedulePeriod");
  5279. pch = strtok(loc ,"{");
  5280. while (pch != NULL)
  5281. {
  5282. strcpy(SchedulePeriodList[i], pch);
  5283. pch = strtok (NULL, "{");
  5284. i = i + 1;
  5285. }
  5286. n_SchedulePeriods = i;
  5287. for(int i=0;i<n_SchedulePeriods;i++)
  5288. {
  5289. //*************startPeriod****************/
  5290. c = 0;
  5291. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5292. memset(sstr ,0, sizeof(sstr) );
  5293. while (loc[strlen("startPeriod")+2+c] != ',')
  5294. {
  5295. sstr[c] = loc[strlen("startPeriod")+2+c];
  5296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5297. c++;
  5298. }
  5299. sstr[c] = '\0';
  5300. tempStartPeriodInt = atoi(sstr);
  5301. //*************limit****************/
  5302. c = 0;
  5303. loc = strstr(SchedulePeriodList[i], "limit");
  5304. memset(sstr ,0, sizeof(sstr) );
  5305. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5306. {
  5307. sstr[c] = loc[strlen("limit")+2+c];
  5308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5309. c++;
  5310. }
  5311. sstr[c] = '\0';
  5312. tempLimitInt = atof(sstr);
  5313. //*************numberPhases****************/
  5314. c = 0;
  5315. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5316. memset(sstr ,0, sizeof(sstr) );
  5317. if(loc != NULL)
  5318. {
  5319. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5320. {
  5321. sstr[c] = loc[strlen("numberPhases")+2+c];
  5322. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5323. c++;
  5324. }
  5325. sstr[c] = '\0';
  5326. tempNumberPhasesInt = atoi(sstr);
  5327. }
  5328. else
  5329. {
  5330. tempNumberPhasesInt = 0;
  5331. }
  5332. if(j == 0)
  5333. {
  5334. TxDefaultProfile.Duration = tempdurationInt;
  5335. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5336. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5337. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5338. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5339. }
  5340. else
  5341. {
  5342. //other stack level charging Profile
  5343. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5344. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5345. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5346. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5347. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5348. }
  5349. }
  5350. if(MinChargingRate < tempminChargingRateFloat)
  5351. MinChargingRate = tempminChargingRateFloat;
  5352. if(confirmPeriods < n_SchedulePeriods)
  5353. confirmPeriods = n_SchedulePeriods;
  5354. j = j + 1;
  5355. //DEBUG_INFO(" 1-2\n");
  5356. }
  5357. fclose(fptr1);
  5358. //Stacking Charging Profiles
  5359. for(int l=0; l <(j-1) ;l++)
  5360. {
  5361. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5362. {
  5363. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5364. {
  5365. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5366. {
  5367. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5368. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5369. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5370. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5371. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5372. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5373. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5374. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5375. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5376. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5377. }
  5378. else
  5379. {
  5380. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5381. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5382. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5383. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5384. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5385. }
  5386. }
  5387. }
  5388. }
  5389. //end of Stacking Charging Profiles
  5390. }
  5391. }// the end of ACCESS TxDefaultProfile
  5392. //****************************TxProfile************************************************/
  5393. memset(fname, 0, sizeof fname);
  5394. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5395. TxProfileIsNull=TRUE;
  5396. if((access(fname,F_OK))!=-1)
  5397. {
  5398. fptr1 = fopen(fname, "r");
  5399. c = 0;
  5400. c = fgetc(fptr1);
  5401. //DEBUG_INFO("c:%d\n",c);
  5402. rewind(fptr1);
  5403. if(c == EOF)
  5404. {
  5405. DEBUG_INFO("\n End of file reached.");
  5406. TxProfileIsNull=TRUE;
  5407. fclose(fptr1);
  5408. }
  5409. else
  5410. {
  5411. TxProfileIsNull=FALSE;
  5412. while(fscanf(fptr1, "%s", word) != EOF)
  5413. {
  5414. if(strcmp(word, "chargingProfileId") == 0)
  5415. {
  5416. n_chargingProfile = n_chargingProfile + 1;
  5417. }
  5418. }
  5419. rewind(fptr1);
  5420. //search Charging Profile Element
  5421. int i= 0;
  5422. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5423. #if 0
  5424. /***********connectorId****************/
  5425. c = 0;
  5426. loc = strstr(sLineWord, "connectorId");
  5427. memset(sstr ,0, sizeof(sstr) );
  5428. while (loc[strlen("connectorId")+2+c] != ',')
  5429. {
  5430. sstr[c] = loc[strlen("connectorId")+2+c];
  5431. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5432. c++;
  5433. }
  5434. sstr[c] = '\0';
  5435. tempconnectorIdInt = atoi(sstr);
  5436. #endif
  5437. //***********validFrom**************/
  5438. c = 0;
  5439. loc = strstr(sLineWord, "validFrom");
  5440. if(loc != NULL)
  5441. {
  5442. memset(sstr ,0, sizeof(sstr) );
  5443. while (loc[3+strlen("validFrom")+c] != '\"')
  5444. {
  5445. sstr[c] = loc[3+strlen("validFrom")+c];
  5446. c++;
  5447. }
  5448. sstr[c] = '\0';
  5449. strcpy(tempvalidFromStr,sstr);
  5450. }
  5451. else
  5452. {
  5453. strcpy(tempvalidFromStr,"");
  5454. }
  5455. //**********startSchedule**********/
  5456. c = 0;
  5457. loc = strstr(sLineWord, "startSchedule");
  5458. memset(sstr ,0, sizeof(sstr) );
  5459. while (loc[3+strlen("startSchedule")+c] != '\"')
  5460. {
  5461. sstr[c] = loc[3+strlen("startSchedule")+c];
  5462. c++;
  5463. }
  5464. sstr[c] = '\0';
  5465. strcpy(tempstartScheduleStr, sstr);
  5466. strcpy(TxProfileScheduleStr, sstr);
  5467. //**********chargingRateUnit**********/
  5468. c = 0;
  5469. loc = strstr(sLineWord, "chargingRateUnit");
  5470. memset(sstr ,0, sizeof(sstr) );
  5471. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5472. {
  5473. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5474. c++;
  5475. }
  5476. sstr[c] = '\0';
  5477. strcpy(tempchargingRateUnitStr, sstr);
  5478. //**********minChargingRate*******/
  5479. c = 0;
  5480. loc = strstr(sLineWord, "minChargingRate");
  5481. if(loc != NULL)
  5482. {
  5483. memset(sstr ,0, sizeof(sstr) );
  5484. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5485. {
  5486. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5487. c++;
  5488. }
  5489. sstr[c] = '\0';
  5490. tempminChargingRateFloat = atof(sstr);
  5491. }
  5492. else
  5493. {
  5494. tempminChargingRateFloat = 0.0;
  5495. }
  5496. #if 0
  5497. //
  5498. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5499. tp.tm_isdst = -1;
  5500. time_t utc = mktime(&tp);
  5501. time_t t = time(NULL);
  5502. //diff_t = difftime(t, utc);
  5503. #endif
  5504. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5505. //parsing strings to words
  5506. i = 0;
  5507. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5508. loc = loc+3+strlen("chargingSchedulePeriod");
  5509. pch = strtok(loc ,"{");
  5510. while (pch != NULL)
  5511. {
  5512. strcpy(SchedulePeriodList[i], pch);
  5513. pch = strtok (NULL, "{");
  5514. i = i + 1;
  5515. }
  5516. n_SchedulePeriods = i;
  5517. for(int i=0;i<n_SchedulePeriods;i++)
  5518. {
  5519. //*************startPeriod****************/
  5520. c = 0;
  5521. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5522. memset(sstr ,0, sizeof(sstr) );
  5523. while (loc[strlen("startPeriod")+2+c] != ',')
  5524. {
  5525. sstr[c] = loc[strlen("startPeriod")+2+c];
  5526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5527. c++;
  5528. }
  5529. sstr[c] = '\0';
  5530. tempStartPeriodInt = atoi(sstr);
  5531. //*************limit****************/
  5532. c = 0;
  5533. loc = strstr(SchedulePeriodList[i], "limit");
  5534. memset(sstr ,0, sizeof(sstr) );
  5535. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5536. {
  5537. sstr[c] = loc[strlen("limit")+2+c];
  5538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5539. c++;
  5540. }
  5541. sstr[c] = '\0';
  5542. tempLimitInt = atof(sstr);
  5543. //*************numberPhases****************/
  5544. c = 0;
  5545. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5546. memset(sstr ,0, sizeof(sstr) );
  5547. if(loc != NULL)
  5548. {
  5549. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5550. {
  5551. sstr[c] = loc[strlen("numberPhases")+2+c];
  5552. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5553. c++;
  5554. }
  5555. sstr[c] = '\0';
  5556. tempNumberPhasesInt = atoi(sstr);
  5557. }
  5558. else
  5559. {
  5560. tempNumberPhasesInt = 0;
  5561. }
  5562. TxProfile.Duration = durationInt;
  5563. TxProfile.TotalPeriod = n_SchedulePeriods;
  5564. TxProfile.Period[i].Limit = tempLimitInt;
  5565. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5566. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5567. }
  5568. if(MinChargingRate < tempminChargingRateFloat)
  5569. MinChargingRate = tempminChargingRateFloat;
  5570. if(confirmPeriods < n_SchedulePeriods)
  5571. confirmPeriods = n_SchedulePeriods;
  5572. }
  5573. fclose(fptr1);
  5574. }
  5575. }// the end of ACCESS TxProfile
  5576. //CompositeSchedule
  5577. int period=0;
  5578. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5579. {
  5580. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5581. struct tm tp;
  5582. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5583. tp.tm_isdst = -1;
  5584. time_t utc = mktime(&tp);
  5585. time_t t = time(NULL);
  5586. double diff_f = difftime(t, utc);
  5587. int diff_i; // = (int)diff_f;
  5588. int quotient; // = diff_i / 86400;//86400 seconds/day
  5589. //int remainder = diff_i % 86400;
  5590. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5591. {
  5592. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5593. {
  5594. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5595. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5596. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5597. period = period + 1;
  5598. }
  5599. else
  5600. {
  5601. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5602. {
  5603. }
  5604. else
  5605. {
  5606. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5607. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5608. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5609. period = period + 1;
  5610. }
  5611. }
  5612. }
  5613. if( diff_f >= 0)
  5614. {
  5615. diff_i = (int)diff_f;
  5616. quotient = diff_i / 86400;//86400 seconds/day
  5617. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5618. {
  5619. 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))
  5620. {
  5621. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5622. {
  5623. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5624. }
  5625. else
  5626. {
  5627. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5628. }
  5629. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5630. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5631. period = period + 1;
  5632. }
  5633. }
  5634. // Check Last Period
  5635. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5636. {
  5637. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5638. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5639. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5640. period = period + 1;
  5641. }
  5642. } // diff_f >= 0
  5643. }
  5644. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5645. {
  5646. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5647. struct tm tp;
  5648. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5649. tp.tm_isdst = -1;
  5650. time_t utc = mktime(&tp);
  5651. time_t t = time(NULL);
  5652. double diff_f = difftime(t, utc);
  5653. int diff_i;// = (int)diff_f;
  5654. int quotient; // = diff_i / 86400;//86400 seconds/day
  5655. //int remainder = diff_i % 86400;
  5656. if(diff_f >= 0)
  5657. {
  5658. diff_i = (int)diff_f;
  5659. quotient = diff_i / 86400;//86400 seconds/day
  5660. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5661. {
  5662. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5663. {
  5664. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5665. {
  5666. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5667. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5668. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5669. period = period + 1;
  5670. }
  5671. else
  5672. {
  5673. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5674. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5675. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5676. period = period + 1;
  5677. }
  5678. }
  5679. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5680. {
  5681. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5682. {
  5683. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5684. {
  5685. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5686. {
  5687. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5688. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5689. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5690. period = period + 1;
  5691. }
  5692. else
  5693. {
  5694. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5695. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5696. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5697. period = period + 1;
  5698. }
  5699. }
  5700. }
  5701. }
  5702. }
  5703. } // end diff_f >= 0
  5704. }
  5705. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5706. {
  5707. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5708. struct tm tp;
  5709. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5710. tp.tm_isdst = -1;
  5711. time_t utc = mktime(&tp);
  5712. time_t t = time(NULL);
  5713. double diff_f = difftime(t, utc);
  5714. int diff_i; // = (int)diff_f;
  5715. int quotient; // = diff_i / 86400;//86400 seconds/day
  5716. //int remainder = diff_i % 86400;
  5717. if(diff_f >= 0)
  5718. {
  5719. diff_i = (int)diff_f;
  5720. quotient = diff_i / 86400;//86400 seconds/day
  5721. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5722. {
  5723. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5724. {
  5725. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5726. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5727. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5728. period = period + 1;
  5729. }
  5730. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5731. {
  5732. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5733. {
  5734. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5735. {
  5736. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5737. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5738. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5739. period = period + 1;
  5740. }
  5741. }
  5742. }
  5743. }
  5744. } // diff_f >= 0
  5745. }
  5746. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5747. {
  5748. confirmPeriods = 0;
  5749. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5750. goto end;
  5751. }
  5752. confirmPeriods = period;
  5753. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5754. //---- Define StartSchedule----/
  5755. struct tm *gtime;
  5756. time_t now;
  5757. char buf[28];
  5758. //---Read the current system time---/
  5759. time(&now);
  5760. //---Convert the system time to GMT (now UTC)---/
  5761. gtime = gmtime(&now);
  5762. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5763. // make .conf
  5764. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5765. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5766. //DEBUG_INFO(" debug 11\n");
  5767. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5768. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5769. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5770. }
  5771. else
  5772. {
  5773. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5774. }
  5775. end:
  5776. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5777. return result;
  5778. }
  5779. int handleGetConfigurationRequest(char *uuid, char *payload)
  5780. {
  5781. mtrace();
  5782. int result = FAIL;
  5783. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5784. //struct json_object *jsonitem;
  5785. int MaxKeySupported = 0;
  5786. int n_keys = 0;
  5787. char requestKey[43][50]={0};
  5788. char search[]="[";
  5789. char sstr[500]={ 0 };
  5790. //int pos;
  5791. int l, c = 0;
  5792. int i = 0;
  5793. char *delim = "\",\"";
  5794. char * pch;
  5795. char *loc = strstr(payload, search);
  5796. //********************* Parsing String ***********************************/
  5797. if(loc == NULL) {
  5798. DEBUG_INFO("no key match in Configuration \n");
  5799. }
  5800. else {
  5801. //pos = loc - payload;
  5802. l = strlen(loc)-4;
  5803. while (c < l)
  5804. {
  5805. sstr[c] = loc[c+2];
  5806. c++;
  5807. }
  5808. sstr[c] = '\0';
  5809. //parsing strings to words
  5810. pch = strtok(sstr,delim);
  5811. if(pch == NULL)
  5812. {
  5813. strcpy(requestKey[0], sstr);
  5814. }
  5815. else
  5816. {
  5817. while (pch != NULL)
  5818. {
  5819. strcpy(requestKey[i], pch);
  5820. pch = strtok (NULL, delim);
  5821. i = i + 1;
  5822. }
  5823. n_keys = i;
  5824. }
  5825. }
  5826. UnknownKeynum = 0;
  5827. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5828. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5829. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5830. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5831. if(n_keys != 0)
  5832. {
  5833. for(int i=0;i<n_keys;i++)
  5834. {
  5835. getKeyValue(requestKey[i]);
  5836. //json_object_put(jsonitem);
  5837. }
  5838. }
  5839. else
  5840. {
  5841. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5842. getKeyValue("");
  5843. }
  5844. processUnkownKey();
  5845. sendGetConfigurationConfirmation(uuid);
  5846. return result;
  5847. }
  5848. static char fnamePlusPath[100]={0};
  5849. static char fnamePWithNoPath[60]={0};
  5850. void checkUploadLog(void)
  5851. {
  5852. FILE *fp;
  5853. /* Open the command for reading. */
  5854. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5855. if (fp == NULL) {
  5856. printf("Failed to run command\n" );
  5857. exit(1);
  5858. }
  5859. int ftppathlen = 0;
  5860. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5861. int i = 0;
  5862. /* Read the output a line at a time - output it. */
  5863. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5864. if(i==0)
  5865. {
  5866. ftppathlen = strlen(fnamePlusPath);
  5867. printf("%s\n", fnamePlusPath);
  5868. fnamePlusPath[ftppathlen]='\0';
  5869. break;
  5870. }
  5871. i= i+1;
  5872. }
  5873. /* close */
  5874. pclose(fp);
  5875. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5876. {
  5877. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5878. {
  5879. fnamePlusPath[k]='\0';
  5880. }
  5881. }
  5882. i=1;
  5883. //char fname[60]={0};
  5884. while(i < ftppathlen)
  5885. {
  5886. int len=ftppathlen-i;
  5887. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5888. {
  5889. printf("compare '/' all right\n");
  5890. break;
  5891. }
  5892. i=i+1;
  5893. }
  5894. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5895. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5896. fnamePWithNoPath[i+1] = '\0';
  5897. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5898. {
  5899. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5900. {
  5901. fnamePWithNoPath[j]='\0';
  5902. }
  5903. }
  5904. FILE* fp1 = fopen(fnamePlusPath, "r");
  5905. if (fp1)
  5906. {
  5907. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5908. // file exists
  5909. fclose(fp1);
  5910. }
  5911. else
  5912. {
  5913. // file doesn't exist
  5914. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5915. }
  5916. }
  5917. static char GetDiagnosticspayloadData[300]={0};
  5918. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5919. {
  5920. mtrace();
  5921. int result = FAIL;
  5922. pthread_t t; // pthread 變數
  5923. system("exec /root/logPackTools 'log' 6");
  5924. #if 0
  5925. //char buffer [128];
  5926. time (&rawtime);
  5927. //printf("%ld\n", rawtime);
  5928. timeinfo = localtime (&rawtime);
  5929. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5930. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5931. if((access(fnamePlusPath,F_OK))!=-1)
  5932. {
  5933. DEBUG_INFO("fnamePlusPath exist.\n");
  5934. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5935. }
  5936. else
  5937. {
  5938. DEBUG_INFO("fnamePlusPath not exist!\n");
  5939. }
  5940. #endif
  5941. checkUploadLog();
  5942. memset(GetDiagnosticspayloadData, 0, 300);
  5943. strcpy(GetDiagnosticspayloadData, payload);
  5944. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5945. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5946. return result;
  5947. }
  5948. void* GetDiagnosticsProcess(void* data)
  5949. {
  5950. pthread_detach(pthread_self());
  5951. mtrace();
  5952. int retriesInt=0, retryIntervalInt=0;
  5953. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5954. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5955. 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};
  5956. int port=0;
  5957. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5958. int c = 0;
  5959. char *loc;
  5960. int isSuccess = FALSE;
  5961. char ftpbuf[200]={0};
  5962. //char temp[100]={0};
  5963. char * pch;
  5964. // [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"}]
  5965. char str[300]={ 0 };
  5966. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5967. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5968. DEBUG_INFO("GetDiagnosticsProcess\n");
  5969. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5970. //****************location*******************/
  5971. c = 0;
  5972. memset(sstr ,0, sizeof(sstr) );
  5973. loc = strstr(str, "location");
  5974. while (loc[3+strlen("location")+c] != '\"')
  5975. {
  5976. sstr[c] = loc[3+strlen("location")+c];
  5977. c++;
  5978. }
  5979. sstr[c] = '\0';
  5980. strcpy(locationstr,sstr);
  5981. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5982. if(strcmp(locationstr,"")==0)
  5983. {
  5984. DEBUG_INFO("location is <Empty>!\n");
  5985. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5986. goto end;
  5987. }
  5988. //****************retries*******************/
  5989. c = 0;
  5990. loc = strstr(str, "retries");
  5991. if(loc == NULL)
  5992. {
  5993. retriesIsNULL = TRUE;
  5994. }
  5995. else
  5996. {
  5997. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5998. {
  5999. sstr[c] = loc[strlen("retries")+2+c];
  6000. c++;
  6001. }
  6002. sstr[c] = '\0';
  6003. retriesInt = atoi(sstr);
  6004. }
  6005. if(retriesIsNULL == TRUE)
  6006. {
  6007. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6008. }
  6009. //****************retryInterval*******************/
  6010. c = 0;
  6011. loc = strstr(str, "retryInterval");
  6012. if(loc == NULL)
  6013. {
  6014. retryIntervalIsNULL = TRUE;
  6015. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6016. }
  6017. else
  6018. {
  6019. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6020. {
  6021. sstr[c] = loc[strlen("retryInterval")+2+c];
  6022. c++;
  6023. }
  6024. sstr[c] = '\0';
  6025. retryIntervalInt = atoi(sstr);
  6026. }
  6027. //****************startTime*******************/
  6028. c = 0;
  6029. memset(sstr ,0, sizeof(sstr) );
  6030. loc = strstr(str, "startTime");
  6031. if(loc == NULL)
  6032. {
  6033. startTimeIsNULL = TRUE;
  6034. }
  6035. else
  6036. {
  6037. while (loc[3+strlen("startTime")+c] != '\"')
  6038. {
  6039. sstr[c] = loc[3+strlen("startTime")+c];
  6040. c++;
  6041. }
  6042. sstr[c] = '\0';
  6043. strcpy(startTimestr,sstr);
  6044. }
  6045. //****************stopTime*******************/
  6046. c = 0;
  6047. memset(sstr ,0, sizeof(sstr) );
  6048. loc = strstr(str, "stopTime");
  6049. if(loc == NULL)
  6050. {
  6051. stopTimeIsNULL = TRUE;
  6052. }
  6053. else
  6054. {
  6055. while (loc[3+strlen("stopTime")+c] != '\"')
  6056. {
  6057. sstr[c] = loc[3+strlen("stopTime")+c];
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. strcpy(stopTimestr,sstr);
  6062. }
  6063. memset(protocol, 0, sizeof(protocol));
  6064. memset(user, 0, sizeof(user) );
  6065. memset(password, 0, sizeof(password));
  6066. memset(host, 0, sizeof(host));
  6067. memset(path, 0, sizeof(path));
  6068. memset(ftppath, 0, sizeof(ftppath));
  6069. memset(host1, 0, sizeof(host1));
  6070. memset(path1, 0, sizeof(path1));
  6071. /*location: ftp://user:password@host:port/path*/
  6072. #if 0
  6073. time_t rawtime;
  6074. struct tm * timeinfo;
  6075. //char buffer [128];
  6076. time (&rawtime);
  6077. //printf("%ld\n", rawtime);
  6078. timeinfo = localtime (&rawtime);
  6079. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6080. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6081. #endif
  6082. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6083. if((access(fnamePlusPath,F_OK))!=-1)
  6084. {
  6085. DEBUG_INFO("fnamePlusPath exist.\n");
  6086. }
  6087. else
  6088. {
  6089. DEBUG_INFO("fnamePlusPath not exist!\n");
  6090. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6091. goto end;
  6092. }
  6093. pch=strchr(locationstr,'@');
  6094. if(pch==NULL)
  6095. {
  6096. sscanf(locationstr,
  6097. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6098. protocol, host, &port, path);
  6099. strcpy(user,"anonymous");
  6100. strcpy(password,"");
  6101. }
  6102. else
  6103. {
  6104. //DEBUG_INFO("pch=%s\n", pch);
  6105. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6106. protocol, user, password, host, &port, path);
  6107. }
  6108. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6109. {
  6110. DEBUG_INFO("protocol is not ftp/http ! \n");
  6111. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6112. goto end;
  6113. }
  6114. if(strncmp(locationstr,"http", 4) == 0)
  6115. {
  6116. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6117. sprintf(ftppath,"/%s", path);
  6118. do{
  6119. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6120. sleep(retryIntervalInt);
  6121. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6122. if(!isSuccess)
  6123. {
  6124. DEBUG_INFO("Diagnostics fail.\n");
  6125. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6126. }
  6127. else
  6128. {
  6129. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6130. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6131. }
  6132. }
  6133. else
  6134. {
  6135. sscanf(host,"%[^/]%s",host1, path1);
  6136. sprintf(ftppath,"%s", path1);
  6137. int ftppathlen=strlen(ftppath);
  6138. int i=1;
  6139. char filenametemp[50];
  6140. while(i < ftppathlen)
  6141. {
  6142. int len=ftppathlen-i;
  6143. if(ftppath[len]== 47) // '/' ascll code: 47
  6144. {
  6145. DEBUG_INFO("find '/' all right\n");
  6146. break;
  6147. }
  6148. i=i+1;
  6149. }
  6150. memset(filenametemp, 0, sizeof(filenametemp));
  6151. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6152. filenametemp[i+1] = 0;
  6153. memset(ftpbuf, 0, sizeof(ftpbuf));
  6154. if(port == 0)
  6155. port = 21;
  6156. do{
  6157. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6158. sleep(retryIntervalInt);
  6159. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6160. if(!isSuccess)
  6161. {
  6162. DEBUG_INFO("Diagnostics fail.\n");
  6163. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6164. }
  6165. else
  6166. {
  6167. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6168. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6169. }
  6170. }
  6171. end:
  6172. DiagnosticsStatusNotificationStatus = 0; //Idle
  6173. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6174. }
  6175. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6176. {
  6177. mtrace();
  6178. int result = FAIL;
  6179. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6180. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6181. {
  6182. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6183. localversion = -1;
  6184. }
  6185. else
  6186. {
  6187. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6188. OCPP_getListVerion();
  6189. }
  6190. //from db.OCPP_getListVerion
  6191. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6192. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6193. sendGetLocalListVersionConfirmation(uuid,"");
  6194. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6195. return result;
  6196. }
  6197. int handleRemoteStartRequest(char *uuid, char *payload)
  6198. {
  6199. mtrace();
  6200. int result = FAIL;
  6201. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6202. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6203. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6204. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6205. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6206. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6207. int chargingSchedulePeriodCount = 0;
  6208. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6209. int c = 0;
  6210. char *loc;
  6211. char comfirmstr[20]={0};
  6212. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6213. if(server_pending == TRUE)
  6214. {
  6215. return 0;
  6216. }
  6217. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6218. //**********connectorId****************/
  6219. c = 0;
  6220. memset(sstr ,0, sizeof(sstr) );
  6221. loc = strstr(payload, "connectorId");
  6222. if(loc == NULL)
  6223. {
  6224. connectorIdIsNULL = TRUE;
  6225. }
  6226. else
  6227. {
  6228. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6229. {
  6230. sstr[c] = loc[strlen("connectorId")+2+c];
  6231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6232. c++;
  6233. }
  6234. sstr[c] = '\0';
  6235. connectorIdInt = atoi(sstr);
  6236. }
  6237. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6238. {
  6239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6240. goto end;
  6241. }
  6242. //****************idTag*******************/
  6243. c = 0;
  6244. memset(sstr ,0, sizeof(sstr) );
  6245. loc = strstr(payload, "idTag");
  6246. while (loc[3+strlen("idTag")+c] != '\"')
  6247. {
  6248. sstr[c] = loc[3+strlen("idTag")+c];
  6249. c++;
  6250. }
  6251. sstr[c] = '\0';
  6252. strcpy(idTagstr,sstr);
  6253. //****************chargingProfile*******************/
  6254. c = 0;
  6255. memset(sstr ,0, sizeof(sstr) );
  6256. loc = strstr(payload, "chargingProfile");
  6257. if(loc == NULL)
  6258. {
  6259. chargingProfileIsNULL = TRUE;
  6260. }
  6261. else
  6262. {
  6263. //****************chargingProfileId*******************/
  6264. c=0;
  6265. loc = strstr(payload, "chargingProfileId");
  6266. memset(sstr ,0, sizeof(sstr) );
  6267. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6268. {
  6269. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6271. c++;
  6272. }
  6273. sstr[c] = '\0';
  6274. chargingProfileIdInt = atoi(sstr);
  6275. //****************transactionId*******************/
  6276. loc = strstr(payload, "transactionId");
  6277. if(loc == NULL)
  6278. {
  6279. transactionIdIsNULL = TRUE;
  6280. }
  6281. else
  6282. {
  6283. c=0;
  6284. memset(sstr ,0, sizeof(sstr) );
  6285. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6286. {
  6287. sstr[c] = loc[strlen("transactionId")+2+c];
  6288. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6289. c++;
  6290. }
  6291. sstr[c] = '\0';
  6292. transactionIdInt = atoi(sstr);
  6293. }
  6294. //****************stackLevel*******************/
  6295. c=0;
  6296. loc = strstr(payload, "stackLevel");
  6297. memset(sstr ,0, sizeof(sstr) );
  6298. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6299. {
  6300. sstr[c] = loc[strlen("stackLevel")+2+c];
  6301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6302. c++;
  6303. }
  6304. sstr[c] = '\0';
  6305. stackLevelInt = atoi(sstr);
  6306. //****************chargingProfilePurpose*******************/
  6307. c = 0;
  6308. memset(sstr ,0, sizeof(sstr) );
  6309. loc = strstr(payload, "chargingProfilePurpose");
  6310. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6311. {
  6312. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6313. c++;
  6314. }
  6315. sstr[c] = '\0';
  6316. strcpy(chargingProfilePurposestr,sstr);
  6317. //****************chargingProfileKind*******************/
  6318. c = 0;
  6319. memset(sstr ,0, sizeof(sstr) );
  6320. loc = strstr(payload, "chargingProfileKind");
  6321. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6322. {
  6323. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6324. c++;
  6325. }
  6326. sstr[c] = '\0';
  6327. strcpy(chargingProfileKindstr,sstr);
  6328. //****************recurrencyKind*******************/
  6329. loc = strstr(payload, "recurrencyKind");
  6330. if(loc == NULL)
  6331. {
  6332. recurrencyKindIsNULL = TRUE;
  6333. }
  6334. else
  6335. {
  6336. c = 0;
  6337. memset(sstr ,0, sizeof(sstr) );
  6338. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6339. {
  6340. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6341. c++;
  6342. }
  6343. sstr[c] = '\0';
  6344. strcpy(recurrencyKindstr,sstr);
  6345. }
  6346. //****************validFrom*******************/
  6347. loc = strstr(payload, "validFrom");
  6348. if(loc == NULL)
  6349. {
  6350. validFromIsNULL = TRUE;
  6351. }
  6352. else
  6353. {
  6354. c = 0;
  6355. memset(sstr ,0, sizeof(sstr) );
  6356. while (loc[3+strlen("validFrom")+c] != '\"')
  6357. {
  6358. sstr[c] = loc[3+strlen("validFrom")+c];
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. strcpy(validFromstr,sstr);
  6363. }
  6364. //****************validTo*******************/
  6365. loc = strstr(payload, "validTo");
  6366. if(loc == NULL)
  6367. {
  6368. validToIsNULL = TRUE;
  6369. }
  6370. else
  6371. {
  6372. c = 0;
  6373. memset(sstr ,0, sizeof(sstr) );
  6374. while (loc[3+strlen("validTo")+c] != '\"')
  6375. {
  6376. sstr[c] = loc[3+strlen("validTo")+c];
  6377. c++;
  6378. }
  6379. sstr[c] = '\0';
  6380. strcpy(validTostr,sstr);
  6381. }
  6382. //****************chargingSchedule*******************/
  6383. loc = strstr(payload, "chargingSchedule");
  6384. if(loc != NULL)
  6385. {
  6386. //****************duration*******************/
  6387. loc = strstr(payload, "duration");
  6388. if(loc == NULL)
  6389. {
  6390. durationIsNULL = TRUE;
  6391. }
  6392. else
  6393. {
  6394. c=0;
  6395. memset(sstr ,0, sizeof(sstr) );
  6396. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6397. {
  6398. sstr[c] = loc[strlen("duration")+2+c];
  6399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6400. c++;
  6401. }
  6402. sstr[c] = '\0';
  6403. durationInt = atoi(sstr);
  6404. }
  6405. //****************startSchedule******************/
  6406. loc = strstr(payload, "startSchedule");
  6407. if(loc == NULL)
  6408. {
  6409. startScheduleIsNULL = TRUE;
  6410. }
  6411. else
  6412. {
  6413. c = 0;
  6414. memset(sstr ,0, sizeof(sstr) );
  6415. while (loc[3+strlen("startSchedule")+c] != '\"')
  6416. {
  6417. sstr[c] = loc[3+strlen("startSchedule")+c];
  6418. c++;
  6419. }
  6420. sstr[c] = '\0';
  6421. strcpy(startSchedulestr,sstr);
  6422. }
  6423. //****************chargingRateUnit*******************/
  6424. c = 0;
  6425. memset(sstr ,0, sizeof(sstr) );
  6426. loc = strstr(payload, "chargingRateUnit");
  6427. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6428. {
  6429. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6430. c++;
  6431. }
  6432. sstr[c] = '\0';
  6433. strcpy(chargingRateUnitstr,sstr);
  6434. //****************minChargingRate*******************/
  6435. loc = strstr(payload, "minChargingRate");
  6436. if(loc == NULL)
  6437. {
  6438. minChargingRateIsNULL = TRUE;
  6439. }
  6440. else
  6441. {
  6442. c=0;
  6443. memset(sstr ,0, sizeof(sstr) );
  6444. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6445. {
  6446. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6448. c++;
  6449. }
  6450. sstr[c] = '\0';
  6451. minChargingRateflaot = atof(sstr);
  6452. }
  6453. //****************chargingSchedulePeriod count*******************/
  6454. int what_len = strlen("startPeriod");
  6455. char *where = payload;
  6456. while ((where = strstr(where, "startPeriod"))) {
  6457. where += what_len;
  6458. chargingSchedulePeriodCount++;
  6459. }
  6460. where = payload;
  6461. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6462. {
  6463. //****************startPeriod*******************/
  6464. c=0;
  6465. loc = strstr(where, "startPeriod");
  6466. memset(sstr ,0, sizeof(sstr) );
  6467. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6468. {
  6469. sstr[c] = loc[strlen("startPeriod")+2+c];
  6470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6471. c++;
  6472. }
  6473. sstr[c] = '\0';
  6474. startPeriodInt[periodNums] = atoi(sstr);
  6475. //****************limit*******************/
  6476. c=0;
  6477. loc = strstr(where, "limit");
  6478. memset(sstr ,0, sizeof(sstr) );
  6479. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6480. {
  6481. sstr[c] = loc[strlen("limit")+2+c];
  6482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. limitflaot[periodNums] = atof(sstr);
  6487. //****************numberPhases*******************/
  6488. loc = strstr(where, "numberPhases");
  6489. if(loc == NULL)
  6490. {
  6491. numberPhasesIsNULL = TRUE;
  6492. }
  6493. else
  6494. {
  6495. c=0;
  6496. memset(sstr ,0, sizeof(sstr) );
  6497. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6498. {
  6499. sstr[c] = loc[strlen("numberPhases")+2+c];
  6500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6501. c++;
  6502. }
  6503. sstr[c] = '\0';
  6504. numberPhasesInt[periodNums] = atoi(sstr);
  6505. }
  6506. where = loc;
  6507. }
  6508. }
  6509. }
  6510. /*
  6511. enum _SYSTEM_STATUS
  6512. {
  6513. S_BOOTING = 0,
  6514. S_IDLE, = 1
  6515. S_AUTHORIZING, =2
  6516. S_REASSIGN_CHECK, =3
  6517. S_REASSIGN, =4
  6518. S_PRECHARGE, =5
  6519. S_PREPARING_FOR_EV, =6
  6520. S_PREPARING_FOR_EVSE, =7
  6521. S_CHARGING, =8
  6522. S_TERMINATING, =9
  6523. S_COMPLETE, =10
  6524. S_ALARM, =11
  6525. S_FAULT =12
  6526. }
  6527. */
  6528. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6529. {
  6530. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6531. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6532. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6533. //check Transaction active
  6534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6535. {
  6536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6537. {
  6538. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6539. {
  6540. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6541. {
  6542. //Reserved
  6543. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6544. }
  6545. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6546. {
  6547. //Reserved
  6548. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6549. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6550. goto end;
  6551. }
  6552. else
  6553. {
  6554. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6555. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6556. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6557. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6558. {
  6559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6560. goto end;
  6561. }
  6562. }//END FOR ELSE
  6563. }
  6564. }// END FOR CHAdeMO_QUANTITY
  6565. for (int index = 0; index < CCS_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6568. {
  6569. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6570. {
  6571. //Reserved
  6572. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6573. }
  6574. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6575. {
  6576. //Reserved
  6577. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6579. goto end;
  6580. }
  6581. else
  6582. {
  6583. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6584. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6585. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6586. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6587. {
  6588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6589. goto end;
  6590. }
  6591. }// END FOR ELSE
  6592. }
  6593. }// END FOR CCS_QUANTITY
  6594. for (int index = 0; index < GB_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6597. {
  6598. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6599. {
  6600. //Reserved
  6601. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6602. }
  6603. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6604. {
  6605. //Reserved
  6606. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6607. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6608. goto end;
  6609. }
  6610. else
  6611. {
  6612. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6613. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6614. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6615. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6616. {
  6617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6618. goto end;
  6619. }
  6620. }// END FOR ELSE
  6621. }
  6622. } // END FOR GB_QUANTITY
  6623. }
  6624. else
  6625. {
  6626. for (int index = 0; index < AC_QUANTITY; index++)
  6627. {
  6628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6629. {
  6630. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6631. {
  6632. //Reserved
  6633. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6634. }
  6635. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6636. {
  6637. //Reserved
  6638. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6640. goto end;
  6641. }
  6642. else
  6643. {
  6644. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6645. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6646. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6647. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6648. {
  6649. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6650. goto end;
  6651. }
  6652. }//END FOR ELSE
  6653. }
  6654. }// END FOR AC_QUANTITY
  6655. }
  6656. if(chargingProfileIsNULL == FALSE)
  6657. {
  6658. //ChargingProfile
  6659. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6660. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6661. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6662. if(recurrencyKindIsNULL == FALSE) //OPTION
  6663. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6664. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6665. if(transactionIdIsNULL == FALSE) // OPTION
  6666. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6667. if(validFromIsNULL == FALSE) // OPTION
  6668. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6669. if(validToIsNULL == FALSE) //OPTION
  6670. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6671. //ChargingSchedule
  6672. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6673. if(durationIsNULL == FALSE) //OPTION
  6674. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6675. if(minChargingRateIsNULL == FALSE) //OPTION
  6676. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6677. if(startScheduleIsNULL == FALSE) //OPTION
  6678. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6679. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6680. {
  6681. //ChargingSchedulePeriod
  6682. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6683. if(numberPhasesIsNULL == FALSE)
  6684. {
  6685. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6686. }
  6687. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6688. }
  6689. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6690. {
  6691. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6692. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6693. //memset idTag
  6694. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6695. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6696. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6697. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6698. }
  6699. else
  6700. {
  6701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6702. }
  6703. }
  6704. else
  6705. {
  6706. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6707. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6708. //memset idTag
  6709. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6710. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6711. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6712. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6713. }
  6714. }
  6715. else
  6716. {
  6717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6718. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6719. }
  6720. end:
  6721. if(connectorIdIsNULL == FALSE)
  6722. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6723. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6724. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6725. //OCPP send RemoteStartConfirmation by first.
  6726. sendRemoteStartConfirmation(uuid, comfirmstr);
  6727. return result;
  6728. }
  6729. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. int match = FALSE;
  6734. int GunNO = 0;
  6735. int transactionIdInt=0;
  6736. int transactionIdIsNULL= FALSE;
  6737. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6738. int c = 0;
  6739. char *loc;
  6740. char comfirmstr[20];
  6741. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6742. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6743. if(server_pending == TRUE)
  6744. {
  6745. return 0;
  6746. }
  6747. c=0;
  6748. loc = strstr(payload, "transactionId");
  6749. if(loc == NULL)
  6750. {
  6751. transactionIdIsNULL= TRUE;
  6752. }
  6753. else
  6754. {
  6755. memset(sstr ,0, sizeof(sstr) );
  6756. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6757. {
  6758. sstr[c] = loc[strlen("transactionId")+2+c];
  6759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6760. c++;
  6761. }
  6762. sstr[c] = '\0';
  6763. transactionIdInt = atoi(sstr);
  6764. }
  6765. if(transactionIdIsNULL == FALSE)
  6766. {
  6767. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6768. {
  6769. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6770. {
  6771. //check Transaction active
  6772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6773. {
  6774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6777. {
  6778. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6779. {
  6780. match = TRUE;
  6781. GunNO = gun_index;
  6782. }
  6783. }
  6784. }// END FOR CHAdeMO_QUANTITY
  6785. for (int index = 0; index < CCS_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6788. {
  6789. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6790. {
  6791. match = TRUE;
  6792. GunNO = gun_index;
  6793. }
  6794. }
  6795. }// END FOR CCS_QUANTITY
  6796. for (int index = 0; index < GB_QUANTITY; index++)
  6797. {
  6798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6799. {
  6800. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6801. {
  6802. match = TRUE;
  6803. GunNO = gun_index;
  6804. }
  6805. }
  6806. }// END FOR GB_QUANTITY
  6807. }
  6808. else
  6809. {
  6810. for (int index = 0; index < AC_QUANTITY; index++)
  6811. {
  6812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6813. {
  6814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6815. {
  6816. match = TRUE;
  6817. GunNO = gun_index;
  6818. }
  6819. }
  6820. }// END FOR CHAdeMO_QUANTITY
  6821. }// END FOR AC ELSE
  6822. }// CHECK IF ResponseTransactionId == transactionIdInt
  6823. }//END FOR
  6824. if( match == TRUE)
  6825. {
  6826. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6827. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6828. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6829. }
  6830. else
  6831. {
  6832. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6833. }
  6834. }
  6835. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6836. return result;
  6837. }
  6838. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6839. {
  6840. mtrace();
  6841. int result = FAIL;
  6842. int connectorIdInt=0, reservationIdInt=0;
  6843. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6844. char comfirmstr[20]={0};
  6845. char sstr[180]={ 0 };
  6846. int c = 0;
  6847. char *loc;
  6848. //char *ptr;
  6849. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6850. //***(1)connectorId ****/
  6851. c=0;
  6852. loc = strstr(payload, "connectorId");
  6853. memset(sstr ,0, sizeof(sstr) );
  6854. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6855. {
  6856. sstr[c] = loc[strlen("connectorId")+2+c];
  6857. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6858. c++;
  6859. }
  6860. sstr[c] = '\0';
  6861. connectorIdInt = atoi(sstr);
  6862. //***(2)expiryDate ****/
  6863. loc = strstr(payload, "expiryDate");
  6864. memset(sstr ,0, sizeof(sstr) );
  6865. c = 0;
  6866. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6867. {
  6868. sstr[c] = loc[3+strlen("expiryDate")+c];
  6869. c++;
  6870. }
  6871. sstr[c] = '\0';
  6872. strcpy(expiryDatestr, sstr);
  6873. //***(3)idTag ****/
  6874. loc = strstr(payload, "idTag");
  6875. memset(sstr ,0, sizeof(sstr) );
  6876. c = 0;
  6877. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6878. {
  6879. sstr[c] = loc[3+strlen("idTag")+c];
  6880. c++;
  6881. }
  6882. sstr[c] = '\0';
  6883. strcpy(idTagstr, sstr);
  6884. //***(4)parentIdTag ****/
  6885. loc = strstr(payload, "parentIdTag");
  6886. memset(sstr ,0, sizeof(sstr) );
  6887. c = 0;
  6888. if(loc == NULL)
  6889. {
  6890. strcpy(parentIdTagstr, "");
  6891. }
  6892. else
  6893. {
  6894. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6895. {
  6896. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6897. c++;
  6898. }
  6899. sstr[c] = '\0';
  6900. strcpy(parentIdTagstr, sstr);
  6901. }
  6902. //***(5)reservationId ****/
  6903. c=0;
  6904. loc = strstr(payload, "reservationId");
  6905. memset(sstr ,0, sizeof(sstr) );
  6906. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6907. {
  6908. sstr[c] = loc[strlen("reservationId")+2+c];
  6909. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6910. c++;
  6911. }
  6912. sstr[c] = '\0';
  6913. reservationIdInt = atoi(sstr);
  6914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6915. if(reservationIdInt == 0)
  6916. {
  6917. //reservationId's value can not be 0
  6918. //strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6919. goto end;
  6920. }
  6921. /*
  6922. enum SYSTEM_STATUS
  6923. {
  6924. SYS_MODE_BOOTING = 0,
  6925. SYS_MODE_IDLE = 1,
  6926. SYS_MODE_AUTHORIZING = 2,
  6927. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6928. SYS_MODE_REASSIGN = 4,
  6929. SYS_MODE_PREPARING = 5,
  6930. SYS_MODE_PREPARE_FOR_EV = 6,
  6931. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6932. SYS_MODE_CHARGING = 8,
  6933. SYS_MODE_TERMINATING = 9,
  6934. SYS_MODE_COMPLETE = 10,
  6935. SYS_MODE_ALARM = 11,
  6936. SYS_MODE_FAULT = 12,
  6937. SYS_MODE_RESERVATION = 13,
  6938. SYS_MODE_BOOKING = 14,
  6939. SYS_MODE_MAINTAIN = 15,
  6940. SYS_MODE_DEBUG = 16,
  6941. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6942. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6943. SYS_MODE_UPDATE = 19
  6944. };
  6945. */
  6946. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6947. {
  6948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6949. goto end;
  6950. }
  6951. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6952. {
  6953. //check Transaction active
  6954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6955. {
  6956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6959. {
  6960. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6961. {
  6962. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6963. {
  6964. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6965. {
  6966. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6968. }
  6969. 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'))
  6970. {
  6971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6972. }
  6973. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  6974. {
  6975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6976. }
  6977. else
  6978. {
  6979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6980. }
  6981. }
  6982. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6983. {
  6984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6985. }
  6986. }
  6987. else
  6988. {
  6989. //replace reservation
  6990. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6992. }
  6993. }
  6994. } // END FOR CHAdeMO_QUANTITY
  6995. for (int index = 0; index < CCS_QUANTITY; index++)
  6996. {
  6997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6998. {
  6999. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7000. {
  7001. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7002. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7003. {
  7004. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7005. {
  7006. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7008. }
  7009. 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'))
  7010. {
  7011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7012. }
  7013. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7014. {
  7015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7016. }
  7017. else
  7018. {
  7019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7020. }
  7021. }
  7022. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7023. {
  7024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7025. }
  7026. }
  7027. else
  7028. {
  7029. //replace reservation
  7030. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7032. }
  7033. }
  7034. } // END FOR CCS_QUANTITY
  7035. for (int index = 0; index < GB_QUANTITY; index++)
  7036. {
  7037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7038. {
  7039. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7040. {
  7041. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7042. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7043. {
  7044. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7045. {
  7046. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7048. }
  7049. 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'))
  7050. {
  7051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7052. }
  7053. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7054. {
  7055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7056. }
  7057. else
  7058. {
  7059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7060. }
  7061. }
  7062. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7063. {
  7064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7065. }
  7066. }
  7067. else
  7068. {
  7069. //replace reservation
  7070. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7072. }
  7073. }
  7074. }// END FOR GB_QUANTITY
  7075. }
  7076. else
  7077. {
  7078. for (int index = 0; index < AC_QUANTITY; index++)
  7079. {
  7080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7081. {
  7082. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7083. {
  7084. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7086. {
  7087. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7088. {
  7089. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7091. }
  7092. 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'))
  7093. {
  7094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7095. }
  7096. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7097. {
  7098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7099. }
  7100. else
  7101. {
  7102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7103. }
  7104. }
  7105. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7106. {
  7107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7108. }
  7109. }
  7110. else
  7111. {
  7112. //replace reservation
  7113. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7115. }
  7116. }
  7117. } // END FOR AC_QUANTITY
  7118. }//END FOR AC ELSE
  7119. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7120. }
  7121. else if(connectorIdInt == 0)
  7122. {
  7123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7124. {
  7125. //check Transaction active
  7126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7127. {
  7128. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7129. {
  7130. 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'))
  7131. {
  7132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7133. goto end;
  7134. }
  7135. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7136. {
  7137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7138. goto end;
  7139. }
  7140. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7141. {
  7142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7143. goto end;
  7144. }
  7145. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7146. {
  7147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7148. goto end;
  7149. }
  7150. }
  7151. }// END FOR CHAdeMO_QUANTITY
  7152. for (int index = 0; index < CCS_QUANTITY; index++)
  7153. {
  7154. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7155. {
  7156. 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'))
  7157. {
  7158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7159. }
  7160. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7161. {
  7162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7163. }
  7164. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7165. {
  7166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7167. }
  7168. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7169. {
  7170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7171. }
  7172. }
  7173. } // END FOR CCS_QUANTITY
  7174. for (int index = 0; index < GB_QUANTITY; index++)
  7175. {
  7176. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7177. {
  7178. 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'))
  7179. {
  7180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7181. }
  7182. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7183. {
  7184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7185. }
  7186. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7187. {
  7188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7189. }
  7190. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7191. {
  7192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7193. }
  7194. }
  7195. } // END FOR GB_QUANTITY
  7196. }
  7197. else
  7198. {
  7199. for (int index = 0; index < AC_QUANTITY; index++)
  7200. {
  7201. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7202. {
  7203. 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'))
  7204. {
  7205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7206. goto end;
  7207. }
  7208. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7209. {
  7210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7211. goto end;
  7212. }
  7213. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7214. {
  7215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7216. goto end;
  7217. }
  7218. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7219. {
  7220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7221. goto end;
  7222. }
  7223. }
  7224. }// END FOR AC_QUANTITY
  7225. }
  7226. //The connectorId is 0
  7227. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7229. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7230. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7231. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7232. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7233. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7234. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7235. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7236. result = TRUE;
  7237. return result;
  7238. }
  7239. else
  7240. {
  7241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7242. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7243. }
  7244. if(strcmp(comfirmstr,"Accepted") == 0)
  7245. {
  7246. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7247. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7248. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7249. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7250. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7251. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7252. result = TRUE;
  7253. return result;
  7254. }
  7255. end:
  7256. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7257. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7258. return result;
  7259. }
  7260. int handleResetRequest(char *uuid, char *payload)
  7261. {
  7262. mtrace();
  7263. int result = FAIL;
  7264. char sstr[10]={0};
  7265. char typestr[10]={0};
  7266. char comfirmstr[20]={0};
  7267. int c = 0;
  7268. char *loc;
  7269. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7270. DEBUG_INFO("handleResetRequest ...\n");
  7271. loc = strstr(payload, "type");
  7272. memset(sstr ,0, sizeof(sstr) );
  7273. c = 0;
  7274. while (loc[3+strlen("type")+c] != '\"')
  7275. {
  7276. sstr[c] = loc[3+strlen("type")+c];
  7277. c++;
  7278. }
  7279. sstr[c] = '\0';
  7280. strcpy(typestr,sstr);
  7281. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7282. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7283. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7284. {
  7285. //check Transaction active
  7286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7287. {
  7288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7289. {
  7290. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7291. {
  7292. //0: unplug, 1: Plug-in
  7293. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7294. }
  7295. }
  7296. for (int index = 0; index < CCS_QUANTITY; index++)
  7297. {
  7298. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7299. {
  7300. //0: unplug, 1: Plug-in
  7301. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7302. }
  7303. }
  7304. for (int index = 0; index < GB_QUANTITY; index++)
  7305. {
  7306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7307. {
  7308. //0: unplug, 1: Plug-in
  7309. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7310. }
  7311. }
  7312. }
  7313. else
  7314. {
  7315. for (int index = 0; index < AC_QUANTITY; index++)
  7316. {
  7317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7318. {
  7319. //0: unplug, 1: Plug-in
  7320. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7321. }
  7322. }
  7323. }// END FOR AC ELSE
  7324. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7325. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7326. result = TRUE;
  7327. return result;
  7328. }
  7329. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7330. {
  7331. //check Transaction active
  7332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7333. {
  7334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7335. {
  7336. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7337. {
  7338. //0: unplug, 1: Plug-in
  7339. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7340. }
  7341. }
  7342. for (int index = 0; index < CCS_QUANTITY; index++)
  7343. {
  7344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7345. {
  7346. //0: unplug, 1: Plug-in
  7347. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7348. }
  7349. }
  7350. for (int index = 0; index < GB_QUANTITY; index++)
  7351. {
  7352. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7353. {
  7354. //0: unplug, 1: Plug-in
  7355. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7356. }
  7357. }
  7358. }
  7359. else
  7360. {
  7361. for (int index = 0; index < AC_QUANTITY; index++)
  7362. {
  7363. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7364. {
  7365. //0: unplug, 1: Plug-in
  7366. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7367. }
  7368. }
  7369. }// END FOR AC ELSE
  7370. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7371. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7372. result = TRUE;
  7373. return result;
  7374. }
  7375. else
  7376. {
  7377. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7378. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7379. goto errorend;
  7380. }
  7381. errorend:
  7382. sendResetConfirmation(uuid, comfirmstr);
  7383. return result;
  7384. }
  7385. int handleSendLocalListRequest(char *uuid, char *payload)
  7386. {
  7387. mtrace();
  7388. int result = FAIL;
  7389. int listVersionInt;
  7390. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7391. char listsearch[]="listVersion";
  7392. char updateTypesearch[]="updateType";
  7393. char localAuthorizationListsearch[]="localAuthorizationList";
  7394. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7395. char CardList[500][160]={0};
  7396. char updateTypestr[15]={0};
  7397. char idTagstr[20]={0};
  7398. char parentIdTag[20]={0};
  7399. char expiryDate[30]={0};
  7400. char idTagstatus[16]={0};
  7401. int c = 0;
  7402. int i = 0;
  7403. char *delim1 = "}";
  7404. char * pch;
  7405. char *loc;
  7406. //char *ptr;
  7407. char comfirmstr[20];
  7408. //int n_localAuthorizations = 0;
  7409. int checkState_Faulted = FALSE;
  7410. DEBUG_INFO("handleSendLocalListRequest\n");
  7411. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7412. {
  7413. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7414. goto end;
  7415. }
  7416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7417. {
  7418. //check Charge Point state
  7419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7420. {
  7421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7422. {
  7423. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7424. }
  7425. }
  7426. for (int index = 0; index < CCS_QUANTITY; index++)
  7427. {
  7428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7429. {
  7430. checkState_Faulted = TRUE; //OCPP Status
  7431. }
  7432. }
  7433. for (int index = 0; index < GB_QUANTITY; index++)
  7434. {
  7435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7436. {
  7437. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7438. }
  7439. }
  7440. }
  7441. else
  7442. {
  7443. //check Charge Point state
  7444. for (int index = 0; index < AC_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7447. {
  7448. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7449. }
  7450. }
  7451. }// END FOR AC ELSE
  7452. if(checkState_Faulted == TRUE)
  7453. {
  7454. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7455. goto end;
  7456. }
  7457. //listVersion
  7458. c = 0;
  7459. loc = strstr(payload, listsearch);
  7460. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7461. {
  7462. sstr[c] = loc[strlen("listVersion")+2+c];
  7463. c++;
  7464. }
  7465. sstr[c] = '\0';
  7466. listVersionInt = atoi(sstr);
  7467. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7468. //updateType
  7469. loc = strstr(payload, updateTypesearch);
  7470. c = 0;
  7471. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7472. {
  7473. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7474. c++;
  7475. }
  7476. sstr[c] = '\0';
  7477. strcpy(updateTypestr, sstr);
  7478. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7479. //localAuthorizationList
  7480. memset(sstr ,0, sizeof(sstr) );
  7481. loc = strstr(payload, localAuthorizationListsearch);
  7482. if(loc != NULL) // localAuthorizationList is not NULL
  7483. {
  7484. //Check UpdateType
  7485. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7486. {
  7487. //Local list full update
  7488. printf("Local list full update.\n");
  7489. OCPP_getListVerion();
  7490. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7491. {
  7492. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7493. goto end;
  7494. }
  7495. OCPP_cleanLocalList();
  7496. }
  7497. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7498. {
  7499. //Local list different update
  7500. printf("Local list different update.\n");
  7501. OCPP_getListVerion();
  7502. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7503. {
  7504. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7505. goto end;
  7506. }
  7507. }
  7508. else
  7509. {
  7510. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7511. goto end;
  7512. }
  7513. c = 0;
  7514. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7515. {
  7516. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7518. c++;
  7519. }
  7520. sstr[c] = '\0';
  7521. //DEBUG_INFO("sstr=%s\n", sstr);
  7522. //parsing strings to words
  7523. i = 0;
  7524. pch = strtok(sstr,delim1);
  7525. while (pch != NULL)
  7526. {
  7527. strcpy(CardList[i], pch);
  7528. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7529. pch = strtok (NULL, delim1);
  7530. i = i + 1;
  7531. }
  7532. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7533. //local Authorizations List Numbers
  7534. //n_localAuthorizations = i;
  7535. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7536. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7537. c= 0;
  7538. while(c < i) // i is CardList Number
  7539. {
  7540. //Search "IdToken"
  7541. memset(sstr ,0, sizeof(sstr) );
  7542. loc = strstr(CardList[c], "idTag");
  7543. int j = 0;
  7544. while (loc[3+strlen("idTag")+j] != '\"')
  7545. {
  7546. sstr[j] = loc[3+strlen("idTag")+j];
  7547. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7548. j++;
  7549. }
  7550. sstr[j] = '\0';
  7551. strcpy(idTagstr, sstr);
  7552. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7553. //Search "expiryDate"
  7554. memset(sstr ,0, sizeof(sstr) );
  7555. loc = strstr(CardList[c], "expiryDate");
  7556. j = 0;
  7557. if(loc != NULL)
  7558. {
  7559. while (loc[3+strlen("expiryDate")+j] != '\"')
  7560. {
  7561. sstr[j] = loc[3+strlen("expiryDate")+j];
  7562. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7563. j++;
  7564. }
  7565. sstr[j] = '\0';
  7566. strcpy(expiryDate, sstr);
  7567. }
  7568. else
  7569. {
  7570. strcpy(expiryDate, "");
  7571. }
  7572. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7573. //Search "parentIdTag"
  7574. memset(sstr ,0, sizeof(sstr) );
  7575. loc = strstr(CardList[c], "parentIdTag");
  7576. j = 0;
  7577. if(loc != NULL)
  7578. {
  7579. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7580. {
  7581. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7582. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7583. j++;
  7584. }
  7585. sstr[j] = '\0';
  7586. strcpy(parentIdTag, sstr);
  7587. }
  7588. else
  7589. {
  7590. strcpy(parentIdTag, "");
  7591. }
  7592. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7593. //Search "status"
  7594. memset(sstr ,0, sizeof(sstr) );
  7595. loc = strstr(CardList[c], "status");
  7596. j = 0;
  7597. while (loc[3+strlen("status")+j] != '\"')
  7598. {
  7599. sstr[j] = loc[3+strlen("status")+j];
  7600. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7601. j++;
  7602. }
  7603. sstr[j] = '\0';
  7604. strcpy(idTagstatus, sstr);
  7605. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7606. OCPP_getIdTag(idTagstr);
  7607. //OCPP_getIdTag("test"); For Test
  7608. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7609. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7610. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7611. {
  7612. //Local list full update
  7613. DEBUG_INFO("Local list full update.\n");
  7614. // update list
  7615. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7616. //DEBUG_INFO("Local list full update. 1\n");
  7617. //OCPP_get_TableAuthlocalAllData();
  7618. //DEBUG_INFO("Local list full update. 2\n");
  7619. }
  7620. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7621. {
  7622. #if 0
  7623. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7624. {
  7625. //OCPP_deleteIdTag(idTagstr);
  7626. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7627. }
  7628. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7629. {
  7630. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7631. }
  7632. #endif
  7633. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7634. }
  7635. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7636. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7637. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7638. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7639. c++;
  7640. }
  7641. }
  7642. else
  7643. {
  7644. //Check UpdateType
  7645. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7646. {
  7647. //Local list full update
  7648. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7649. OCPP_cleanLocalList();
  7650. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7651. goto end;
  7652. }
  7653. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7654. {
  7655. //Local list different update
  7656. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7657. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7658. goto end;
  7659. }
  7660. }
  7661. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7662. end:
  7663. sendSendLocalListConfirmation(uuid, comfirmstr);
  7664. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7665. return result;
  7666. }
  7667. #define MAX 200
  7668. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7669. {
  7670. mtrace();
  7671. int result = FAIL;
  7672. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7673. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7674. char chargingProfilePurposeStr[30]={0};
  7675. char chargingProfileKindStr[16]={0};
  7676. char recurrencyKindStr[10]={0};
  7677. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7678. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7679. int chargingSchedulePeriodCount = 0;
  7680. //int updateflag = FALSE;
  7681. char comfirmstr[20]={0};
  7682. int meet= FALSE;
  7683. char sstr[10]={0};
  7684. int c = 0;
  7685. char *loc;
  7686. FILE *fptr1;//, *fptr2;
  7687. //int lno=0;//, linectr = 0;
  7688. //int modifyflag = FALSE;
  7689. char filename[MAX]={0};
  7690. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7691. //int resultRename=0;
  7692. char rmFileCmd[50]={0};
  7693. char tempchargingProfilePurposeStr[30]={0};
  7694. char word[1600]={0};
  7695. int n_chargingProfile = 0;
  7696. //[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}}}]
  7697. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7698. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7699. //*********************connectorId***************************/
  7700. loc = strstr(payload, "connectorId");
  7701. c = 0;
  7702. memset(sstr ,0, sizeof(sstr) );
  7703. while (loc[strlen("connectorId")+2+c] != ',')
  7704. {
  7705. sstr[c] = loc[strlen("connectorId")+2+c];
  7706. c++;
  7707. }
  7708. sstr[c] = '\0';
  7709. connectorIdInt = atoi(sstr);
  7710. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7711. {
  7712. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7713. }
  7714. else
  7715. {
  7716. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7717. }
  7718. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7719. //*********************chargingProfileId***************************/
  7720. loc = strstr(payload, "chargingProfileId");
  7721. c = 0;
  7722. memset(sstr ,0, sizeof(sstr) );
  7723. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7724. {
  7725. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7726. c++;
  7727. }
  7728. sstr[c] = '\0';
  7729. chargingProfileIdInt = atoi(sstr);
  7730. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7731. {
  7732. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7733. }
  7734. else
  7735. {
  7736. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7737. }
  7738. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7739. //*********************transactionId***************************/
  7740. loc = strstr(payload, "transactionId");
  7741. if(loc != NULL)
  7742. {
  7743. c = 0;
  7744. memset(sstr ,0, sizeof(sstr) );
  7745. while (loc[strlen("transactionId")+2+c] != ',')
  7746. {
  7747. sstr[c] = loc[strlen("transactionId")+2+c];
  7748. c++;
  7749. }
  7750. sstr[c] = '\0';
  7751. transactionIdInt = atoi(sstr);
  7752. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7753. {
  7754. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7755. }
  7756. else
  7757. {
  7758. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7759. }
  7760. }
  7761. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7762. //*********************stackLevel***************************/
  7763. loc = strstr(payload, "stackLevel");
  7764. c = 0;
  7765. memset(sstr ,0, sizeof(sstr) );
  7766. while (loc[strlen("stackLevel")+2+c] != ',')
  7767. {
  7768. sstr[c] = loc[strlen("stackLevel")+2+c];
  7769. c++;
  7770. }
  7771. sstr[c] = '\0';
  7772. stackLevelInt = atoi(sstr);
  7773. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7774. {
  7775. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7776. }
  7777. else
  7778. {
  7779. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7780. }
  7781. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7782. //*********************chargingProfilePurpose***************************/
  7783. loc = strstr(payload, "chargingProfilePurpose");
  7784. c = 0;
  7785. memset(sstr ,0, sizeof(sstr) );
  7786. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7787. {
  7788. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7790. c++;
  7791. }
  7792. sstr[c] = '\0';
  7793. strcpy(chargingProfilePurposeStr,sstr);
  7794. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7795. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7796. {
  7797. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7798. }
  7799. else
  7800. {
  7801. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7802. }
  7803. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7804. //*********************chargingProfileKind***************************/
  7805. loc = strstr(payload, "chargingProfileKind");
  7806. c = 0;
  7807. memset(sstr ,0, sizeof(sstr) );
  7808. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7809. {
  7810. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7811. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7812. c++;
  7813. }
  7814. sstr[c] = '\0';
  7815. strcpy(chargingProfileKindStr,sstr);
  7816. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7817. {
  7818. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7819. }
  7820. else
  7821. {
  7822. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7823. }
  7824. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7825. //*********************recurrencyKind***************************/
  7826. loc = strstr(payload, "recurrencyKind");
  7827. if(loc != NULL)
  7828. {
  7829. c = 0;
  7830. memset(sstr ,0, sizeof(sstr) );
  7831. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7832. {
  7833. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7835. c++;
  7836. }
  7837. sstr[c] = '\0';
  7838. strcpy(recurrencyKindStr,sstr);
  7839. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7840. {
  7841. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7842. }
  7843. else
  7844. {
  7845. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7846. }
  7847. }
  7848. else
  7849. {
  7850. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7851. {
  7852. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7853. }
  7854. else
  7855. {
  7856. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7857. }
  7858. }
  7859. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7860. //*********************validFrom***************************/
  7861. loc = strstr(payload, "validFrom");
  7862. if(loc != NULL)
  7863. {
  7864. c = 0;
  7865. memset(sstr ,0, sizeof(sstr) );
  7866. while (loc[3+strlen("validFrom")+c] != '\"')
  7867. {
  7868. sstr[c] = loc[3+strlen("validFrom")+c];
  7869. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7870. c++;
  7871. }
  7872. sstr[c] = '\0';
  7873. strcpy(validFromStr,sstr);
  7874. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7875. {
  7876. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7877. }
  7878. else
  7879. {
  7880. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7881. }
  7882. }
  7883. else
  7884. {
  7885. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7886. {
  7887. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7888. }
  7889. else
  7890. {
  7891. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7892. }
  7893. }
  7894. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7895. //*********************validTo***************************/
  7896. loc = strstr(payload, "validTo");
  7897. if(loc != NULL)
  7898. {
  7899. c = 0;
  7900. memset(sstr ,0, sizeof(sstr) );
  7901. while (loc[3+strlen("validTo")+c] != '\"')
  7902. {
  7903. sstr[c] = loc[3+strlen("validTo")+c];
  7904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7905. c++;
  7906. }
  7907. sstr[c] = '\0';
  7908. strcpy(validToStr,sstr);
  7909. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7910. {
  7911. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7912. }
  7913. else
  7914. {
  7915. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7916. }
  7917. }
  7918. else
  7919. {
  7920. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7921. {
  7922. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7923. }
  7924. else
  7925. {
  7926. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7927. }
  7928. }
  7929. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7930. //*********************duration***************************/
  7931. loc = strstr(payload, "duration");
  7932. if(loc != NULL)
  7933. {
  7934. c = 0;
  7935. memset(sstr ,0, sizeof(sstr) );
  7936. while (loc[strlen("duration")+2+c] != ',')
  7937. {
  7938. sstr[c] = loc[strlen("duration")+2+c];
  7939. c++;
  7940. }
  7941. sstr[c] = '\0';
  7942. durationInt = atoi(sstr);
  7943. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7944. {
  7945. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7946. }
  7947. else
  7948. {
  7949. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7950. }
  7951. }
  7952. else
  7953. {
  7954. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7955. {
  7956. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7957. }
  7958. else
  7959. {
  7960. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7961. }
  7962. }
  7963. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7964. //*********************startSchedule***************************/
  7965. loc = strstr(payload, "startSchedule");
  7966. if(loc != NULL)
  7967. {
  7968. c = 0;
  7969. memset(sstr ,0, sizeof(sstr) );
  7970. while (loc[3+strlen("startSchedule")+c] != '\"')
  7971. {
  7972. sstr[c] = loc[3+strlen("startSchedule")+c];
  7973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7974. c++;
  7975. }
  7976. sstr[c] = '\0';
  7977. strcpy(startScheduleStr,sstr);
  7978. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7979. {
  7980. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7981. }
  7982. else
  7983. {
  7984. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7985. }
  7986. }
  7987. else
  7988. {
  7989. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7990. {
  7991. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7992. }
  7993. else
  7994. {
  7995. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7996. }
  7997. }
  7998. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7999. //*********************chargingRateUnit***************************/
  8000. loc = strstr(payload, "chargingRateUnit");
  8001. if(loc != NULL)
  8002. {
  8003. c = 0;
  8004. memset(sstr ,0, sizeof(sstr) );
  8005. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8006. {
  8007. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8009. c++;
  8010. }
  8011. sstr[c] = '\0';
  8012. strcpy(chargingRateUnitStr,sstr);
  8013. #if 0
  8014. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8015. {
  8016. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8017. goto end;
  8018. }
  8019. #endif
  8020. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8021. {
  8022. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8023. }
  8024. else
  8025. {
  8026. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8027. }
  8028. }
  8029. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8030. //****************chargingSchedulePeriod count start*******************/
  8031. int what_len = strlen("startPeriod");
  8032. char tempChargingProfile[1000]={0};
  8033. strcpy(tempChargingProfile,(const char*)payload);
  8034. char *where = tempChargingProfile;
  8035. if (what_len)
  8036. {
  8037. while ((where = strstr(where, "startPeriod"))) {
  8038. where += what_len;
  8039. chargingSchedulePeriodCount++;
  8040. }
  8041. }
  8042. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8043. {
  8044. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8045. goto end;
  8046. }
  8047. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8048. //where = payload;
  8049. int templength = 0;
  8050. //int searchstart = 0;
  8051. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8052. {
  8053. //****************startPeriod*******************/
  8054. c=0;
  8055. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8056. memset(sstr ,0, sizeof(sstr) );
  8057. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8058. {
  8059. sstr[c] = loc[strlen("startPeriod")+2+c];
  8060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8061. c++;
  8062. }
  8063. sstr[c] = '\0';
  8064. startPeriodInt[periodNums] = atoi(sstr);
  8065. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8066. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8067. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8068. {
  8069. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8070. }
  8071. else
  8072. {
  8073. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8074. }
  8075. templength = strlen("startPeriod")+2+c;
  8076. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8077. //****************limit*******************/
  8078. c=0;
  8079. loc = strstr(tempChargingProfile + templength, "limit");
  8080. memset(sstr ,0, sizeof(sstr) );
  8081. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8082. {
  8083. sstr[c] = loc[strlen("limit")+2+c];
  8084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8085. c++;
  8086. }
  8087. sstr[c] = '\0';
  8088. limitflaot[periodNums] = atof(sstr);
  8089. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8090. {
  8091. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8092. }
  8093. else
  8094. {
  8095. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8096. }
  8097. templength = templength + strlen("limit")+2+c;
  8098. //****************numberPhases*******************/
  8099. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8100. if(loc != NULL)
  8101. {
  8102. c=0;
  8103. memset(sstr ,0, sizeof(sstr) );
  8104. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8105. {
  8106. sstr[c] = loc[strlen("numberPhases")+2+c];
  8107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8108. c++;
  8109. }
  8110. sstr[c] = '\0';
  8111. numberPhasesInt[periodNums] = atoi(sstr);
  8112. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8113. {
  8114. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8115. }
  8116. else
  8117. {
  8118. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8119. }
  8120. templength = templength + strlen("numberPhases")+2+c;
  8121. }
  8122. //where = loc;
  8123. }
  8124. //****************chargingSchedulePeriod count end*******************/
  8125. //*********************minChargingRate***************************/
  8126. loc = strstr(payload, "minChargingRate");
  8127. if(loc != NULL)
  8128. {
  8129. c = 0;
  8130. memset(sstr ,0, sizeof(sstr) );
  8131. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8132. {
  8133. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8134. c++;
  8135. }
  8136. sstr[c] = '\0';
  8137. minChargingRateFloat = atof(sstr);
  8138. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8139. {
  8140. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8141. }
  8142. else
  8143. {
  8144. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8145. }
  8146. }
  8147. else
  8148. {
  8149. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8150. {
  8151. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8152. }
  8153. else
  8154. {
  8155. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8156. }
  8157. }
  8158. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8159. {
  8160. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8161. if(connectorIdInt != 0)
  8162. {
  8163. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8164. goto end;
  8165. }
  8166. strcpy(filename, ChargePointMaxProfile_JSON );
  8167. fptr1 = fopen(filename, "r");
  8168. if (!fptr1)
  8169. {
  8170. //file not exist
  8171. DEBUG_INFO("Unable to open the input file!!\n");
  8172. fptr1 = fopen(filename, "w+");
  8173. }
  8174. else
  8175. {
  8176. //Check Charging Profile Count
  8177. while(fscanf(fptr1, "%s", word) != EOF)
  8178. {
  8179. //DEBUG_INFO("word=%s\n",word);
  8180. if(strstr(word, "chargingProfileId")!= NULL)
  8181. {
  8182. //DEBUG_INFO("test chargingProfileId \n");
  8183. n_chargingProfile = n_chargingProfile + 1;
  8184. //DEBUG_INFO("chargingProfileId Found\n");
  8185. }
  8186. }
  8187. }
  8188. fclose(fptr1);
  8189. }
  8190. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8191. {
  8192. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8193. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8194. {
  8195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8196. goto end;
  8197. }
  8198. memset(filename, 0, sizeof filename);
  8199. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8200. fptr1 = fopen(filename, "r");
  8201. if (!fptr1)
  8202. {
  8203. //file not exist
  8204. //DEBUG_INFO("Unable to open the input file!!\n");
  8205. fptr1 = fopen(filename, "w+");
  8206. }
  8207. else
  8208. {
  8209. //Check Charging Profile Count
  8210. while(fscanf(fptr1, "%s", word) != EOF)
  8211. {
  8212. //DEBUG_INFO("word=%s\n",word);
  8213. if(strstr(word, "chargingProfileId")!= NULL)
  8214. {
  8215. //DEBUG_INFO("test chargingProfileId \n");
  8216. n_chargingProfile = n_chargingProfile + 1;
  8217. //DEBUG_INFO("chargingProfileId Found\n");
  8218. }
  8219. }
  8220. }
  8221. fclose(fptr1);
  8222. }
  8223. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8224. {
  8225. //printf("set chargingProfile 1-4\n");
  8226. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8227. //check Transaction active
  8228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8229. {
  8230. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8231. {
  8232. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8233. {
  8234. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8235. {
  8236. meet = TRUE;
  8237. break;
  8238. }
  8239. }
  8240. }
  8241. }
  8242. for (int index = 0; index < CCS_QUANTITY; index++)
  8243. {
  8244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8245. {
  8246. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[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 < GB_QUANTITY; index++)
  8257. {
  8258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8259. {
  8260. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[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 < AC_QUANTITY; index++)
  8271. {
  8272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  8273. {
  8274. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[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. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8295. fptr1 = fopen(filename, "r");
  8296. if (!fptr1)
  8297. {
  8298. //file not exist
  8299. DEBUG_INFO("Unable to open the input file!!\n");
  8300. fptr1 = fopen(filename, "w+");
  8301. }
  8302. else
  8303. {
  8304. //Check Charging Profile Count
  8305. while(fscanf(fptr1, "%s", word) != EOF)
  8306. {
  8307. //DEBUG_INFO("word=%s\n",word);
  8308. if(strstr(word, "chargingProfileId")!= NULL)
  8309. {
  8310. //DEBUG_INFO("test chargingProfileId \n");
  8311. n_chargingProfile = n_chargingProfile + 1;
  8312. //DEBUG_INFO("chargingProfileId Found\n");
  8313. }
  8314. }
  8315. }
  8316. fclose(fptr1);
  8317. }
  8318. // Check ChargeProfileMaxStackLevel
  8319. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8320. {
  8321. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8322. goto end;
  8323. }
  8324. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8325. {
  8326. int i = 0;
  8327. char fnametemp[200]={0};
  8328. n_chargingProfile = 0;
  8329. //Check ChargePointMaxProfile.json exit
  8330. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8331. {
  8332. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8333. //Check Charging Profile Count
  8334. while(fscanf(fptr1, "%s", word) != EOF)
  8335. {
  8336. //DEBUG_INFO("word=%s\n",word);
  8337. if(strstr(word, "chargingProfileId")!= NULL)
  8338. {
  8339. //DEBUG_INFO("test chargingProfileId \n");
  8340. n_chargingProfile = n_chargingProfile + 1;
  8341. i = i + 1;
  8342. //DEBUG_INFO("chargingProfileId Found\n");
  8343. }
  8344. memset(word, 0, sizeof word);
  8345. }
  8346. fclose(fptr1);
  8347. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8348. }
  8349. //Check TxDefaultProfile_0.json exit
  8350. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8351. {
  8352. i = 0;
  8353. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8354. //Check Charging Profile Count
  8355. while(fscanf(fptr1, "%s", word) != EOF)
  8356. {
  8357. //DEBUG_INFO("word=%s\n",word);
  8358. if(strstr(word, "chargingProfileId")!= NULL)
  8359. {
  8360. //DEBUG_INFO("test chargingProfileId \n");
  8361. n_chargingProfile = n_chargingProfile + 1;
  8362. i = i + 1;
  8363. //DEBUG_INFO("chargingProfileId Found\n");
  8364. }
  8365. memset(word, 0, sizeof word);
  8366. }
  8367. fclose(fptr1);
  8368. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8369. }
  8370. //Check TxDefaultProfile_%d.json
  8371. for(int j=1; j <= gunTotalNumber; j++)
  8372. {
  8373. memset(fnametemp, 0, sizeof fnametemp);
  8374. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8375. if((access(fnametemp,F_OK))!=-1)
  8376. {
  8377. i = 0;
  8378. fptr1 = fopen(fnametemp, "r");
  8379. //Check Charging Profile Count
  8380. while(fscanf(fptr1, "%s", word) != EOF)
  8381. {
  8382. //DEBUG_INFO("word=%s\n",word);
  8383. if(strstr(word, "chargingProfileId")!= NULL)
  8384. {
  8385. //DEBUG_INFO("test chargingProfileId \n");
  8386. n_chargingProfile = n_chargingProfile + 1;
  8387. i = i + 1;
  8388. //DEBUG_INFO("chargingProfileId Found\n");
  8389. }
  8390. memset(word, 0, sizeof word);
  8391. }
  8392. fclose(fptr1);
  8393. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8394. }
  8395. }
  8396. //Check TxProfile_%d.json
  8397. for(int j=1; j <= gunTotalNumber; j++)
  8398. {
  8399. memset(fnametemp, 0, sizeof fnametemp);
  8400. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8401. if((access(fnametemp,F_OK))!=-1)
  8402. {
  8403. i = 0;
  8404. fptr1 = fopen(fnametemp, "r");
  8405. //Check Charging Profile Count
  8406. while(fscanf(fptr1, "%s", word) != EOF)
  8407. {
  8408. //DEBUG_INFO("word=%s\n",word);
  8409. if(strstr(word, "chargingProfileId")!= NULL)
  8410. {
  8411. //DEBUG_INFO("test chargingProfileId \n");
  8412. n_chargingProfile = n_chargingProfile + 1;
  8413. i = i + 1;
  8414. //DEBUG_INFO("chargingProfileId Found\n");
  8415. }
  8416. memset(word, 0, sizeof word);
  8417. }
  8418. fclose(fptr1);
  8419. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8420. }
  8421. }
  8422. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8423. {
  8424. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8425. goto end;
  8426. }
  8427. }
  8428. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8429. //**********************************Write to File********************************************************/
  8430. FILE *infile;
  8431. FILE *outfile;
  8432. // open file for writing
  8433. infile = fopen (filename, "r");
  8434. outfile = fopen (tempfile, "w");
  8435. int d =0;
  8436. d = fgetc(infile);
  8437. //DEBUG_INFO("d:%d\n",d);
  8438. rewind(infile);
  8439. //*检测到文件结束标识返回1,否则返回0。*/
  8440. if(d == EOF)
  8441. {
  8442. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8443. fprintf(outfile,"%s\n",payload);
  8444. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8445. fclose(infile);
  8446. fclose(outfile);
  8447. sprintf(rmFileCmd,"rm -f %s",filename);
  8448. system(rmFileCmd);
  8449. rename(tempfile, filename);
  8450. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8451. //system(rmFileCmd);
  8452. }
  8453. else
  8454. {
  8455. char buf[1000]={0};
  8456. int ChargingProfileAdded = FALSE;
  8457. while (fgets(buf, sizeof(buf), infile) != NULL)
  8458. {
  8459. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8460. //*************************tempconnectorIdInt*********************************/
  8461. loc = strstr(buf, "connectorId");
  8462. c = 0;
  8463. memset(sstr ,0, sizeof(sstr) );
  8464. while (loc[strlen("connectorId")+2+c] != ',')
  8465. {
  8466. sstr[c] = loc[strlen("connectorId")+2+c];
  8467. c++;
  8468. }
  8469. sstr[c] = '\0';
  8470. tempconnectorIdInt = atoi(sstr);
  8471. //*************************tempchargingProfileIdInt*********************************/
  8472. loc = strstr(buf, "chargingProfileId");
  8473. c = 0;
  8474. memset(sstr ,0, sizeof(sstr) );
  8475. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8476. {
  8477. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8478. c++;
  8479. }
  8480. sstr[c] = '\0';
  8481. tempchargingProfileIdInt = atoi(sstr);
  8482. //*************************tempstackLevelInt*********************************/
  8483. loc = strstr(buf, "stackLevel");
  8484. c = 0;
  8485. memset(sstr ,0, sizeof(sstr) );
  8486. while (loc[strlen("stackLevel")+2+c] != ',')
  8487. {
  8488. sstr[c] = loc[strlen("stackLevel")+2+c];
  8489. c++;
  8490. }
  8491. sstr[c] = '\0';
  8492. tempstackLevelInt = atoi(sstr);
  8493. //*************************tempchargingProfilePurposeStr*********************************/
  8494. loc = strstr(payload, "chargingProfilePurpose");
  8495. c = 0;
  8496. memset(sstr ,0, sizeof(sstr) );
  8497. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8498. {
  8499. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. strcpy(tempchargingProfilePurposeStr,sstr);
  8505. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8506. {
  8507. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8508. {
  8509. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8510. if(ChargingProfileAdded == FALSE)
  8511. {
  8512. fprintf(outfile,"%s\n",payload);
  8513. ChargingProfileAdded = TRUE;
  8514. }
  8515. }
  8516. else
  8517. {
  8518. if(tempstackLevelInt < stackLevelInt)
  8519. {
  8520. if(ChargingProfileAdded == FALSE)
  8521. {
  8522. fprintf(outfile,"%s\n",payload);
  8523. ChargingProfileAdded = TRUE;
  8524. fprintf(outfile,"%s\n",buf);
  8525. }
  8526. else
  8527. {
  8528. fprintf(outfile,"%s\n",buf);
  8529. }
  8530. }
  8531. else
  8532. {
  8533. if(ChargingProfileAdded == FALSE)
  8534. {
  8535. fprintf(outfile,"%s\n",buf);
  8536. fprintf(outfile,"%s\n",payload);
  8537. ChargingProfileAdded = TRUE;
  8538. }
  8539. else
  8540. {
  8541. fprintf(outfile,"%s\n",buf);
  8542. }
  8543. }
  8544. }
  8545. }
  8546. else
  8547. {
  8548. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8549. {
  8550. if(ChargingProfileAdded == FALSE)
  8551. {
  8552. fprintf(outfile,"%s\n",payload);
  8553. ChargingProfileAdded = TRUE;
  8554. fprintf(outfile,"%s\n",buf);
  8555. }
  8556. else
  8557. {
  8558. fprintf(outfile,"%s\n",buf);
  8559. }
  8560. }
  8561. else if(tempstackLevelInt < stackLevelInt)
  8562. {
  8563. if(ChargingProfileAdded == FALSE)
  8564. {
  8565. fprintf(outfile,"%s\n",payload);
  8566. ChargingProfileAdded = TRUE;
  8567. fprintf(outfile,"%s\n",buf);
  8568. }
  8569. else
  8570. {
  8571. fprintf(outfile,"%s\n",buf);
  8572. }
  8573. }
  8574. else
  8575. {
  8576. if(ChargingProfileAdded == FALSE)
  8577. {
  8578. fprintf(outfile,"%s\n",buf);
  8579. fprintf(outfile,"%s\n",payload);
  8580. ChargingProfileAdded = TRUE;
  8581. }
  8582. else
  8583. {
  8584. fprintf(outfile,"%s\n",buf);
  8585. }
  8586. }
  8587. }
  8588. } // end of while loop
  8589. fclose(infile);
  8590. fclose(outfile);
  8591. sprintf(rmFileCmd,"rm -f %s",filename);
  8592. system(rmFileCmd);
  8593. rename(tempfile, filename);
  8594. result = TRUE;
  8595. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8596. }
  8597. end:
  8598. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8599. return result;
  8600. return result;
  8601. }
  8602. int handleTriggerMessageRequest(char *uuid, char *payload)
  8603. {
  8604. mtrace();
  8605. int result = FAIL;
  8606. int connectorIdIsNULL = FALSE;
  8607. int connectorIdInt =0;
  8608. char sstr[40]={0};
  8609. char requestedMessagestr[40]={0};
  8610. char comfirmstr[20]={0};
  8611. int c = 0;
  8612. char *loc;
  8613. DEBUG_INFO("handleTriggerMessageRequest\n");
  8614. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8615. c = 0;
  8616. loc = strstr(payload, "requestedMessage");
  8617. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8618. {
  8619. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8620. c++;
  8621. }
  8622. sstr[c] = '\0';
  8623. strcpy(requestedMessagestr, sstr);
  8624. c = 0;
  8625. loc = strstr(payload, "connectorId");
  8626. if(loc == NULL)
  8627. {
  8628. connectorIdIsNULL = TRUE;
  8629. }
  8630. else
  8631. {
  8632. memset(sstr ,0, sizeof(sstr) );
  8633. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8634. {
  8635. sstr[c] = loc[strlen("connectorId")+2+c];
  8636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8637. c++;
  8638. }
  8639. sstr[c] = '\0';
  8640. connectorIdInt = atoi(sstr);
  8641. }
  8642. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8643. {
  8644. //connectorIdInt = json_object_get_int(connectorId);
  8645. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8646. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8647. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8648. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8649. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8650. }
  8651. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8652. {
  8653. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8654. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8655. return TRUE;
  8656. }
  8657. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8658. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8659. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8660. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8661. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8662. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8663. {
  8664. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8665. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8666. return TRUE;
  8667. }
  8668. else
  8669. {
  8670. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8671. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8672. }
  8673. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8674. {
  8675. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8676. {
  8677. FirmwareStatusNotificationStatus = 3;
  8678. }
  8679. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8680. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8681. }
  8682. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8683. {
  8684. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8685. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8686. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8687. }
  8688. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8689. {
  8690. sendBootNotificationRequest();
  8691. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8692. }
  8693. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8694. {
  8695. sendHeartbeatRequest(connectorIdInt);
  8696. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8697. }
  8698. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8699. {
  8700. if(connectorIdIsNULL == FALSE)
  8701. {
  8702. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8703. {
  8704. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8705. sendMeterValuesRequest(connectorIdInt -1);
  8706. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8707. }
  8708. }
  8709. else
  8710. {
  8711. for(int idx=0;idx< gunTotalNumber;idx++)
  8712. {
  8713. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8714. sendMeterValuesRequest(idx);
  8715. }
  8716. }
  8717. }
  8718. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8719. {
  8720. if(connectorIdIsNULL == FALSE)
  8721. {
  8722. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8723. {
  8724. sendStatusNotificationRequest(connectorIdInt -1);
  8725. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8726. }
  8727. }
  8728. else
  8729. {
  8730. for(int idx=0;idx< gunTotalNumber;idx++)
  8731. sendStatusNotificationRequest(idx);
  8732. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8733. }
  8734. }
  8735. return result;
  8736. }
  8737. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8738. {
  8739. mtrace();
  8740. int result = FAIL;
  8741. char sstr[6]={0};
  8742. int connectorIdInt =0;
  8743. char comfirmstr[20]={0};
  8744. int c = 0;
  8745. char *loc;
  8746. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8747. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8748. c = 0;
  8749. loc = strstr(payload, "connectorId");
  8750. memset(sstr ,0, sizeof(sstr) );
  8751. while (loc[strlen("connectorId")+2+c] != '}')
  8752. {
  8753. sstr[c] = loc[strlen("connectorId")+2+c];
  8754. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8755. c++;
  8756. }
  8757. sstr[c] = '\0';
  8758. connectorIdInt = atoi(sstr);
  8759. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8760. if(gunTotalNumber == 0)
  8761. {
  8762. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8763. goto end;
  8764. }
  8765. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8766. {
  8767. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8768. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8769. goto end;
  8770. }
  8771. else
  8772. {
  8773. //check Transaction active
  8774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8775. {
  8776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8777. {
  8778. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8779. {
  8780. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8781. }
  8782. }
  8783. for (int index = 0; index < CCS_QUANTITY; index++)
  8784. {
  8785. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8786. {
  8787. //stop Transaction
  8788. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8789. }
  8790. }
  8791. for (int index = 0; index < GB_QUANTITY; index++)
  8792. {
  8793. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8794. {
  8795. //stop Transaction
  8796. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8797. }
  8798. }
  8799. }
  8800. else
  8801. {
  8802. for (int index = 0; index < AC_QUANTITY; index++)
  8803. {
  8804. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8805. {
  8806. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8807. }
  8808. }
  8809. }// END FOR AC ELSE
  8810. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8811. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8812. result = TRUE;
  8813. return result;
  8814. }
  8815. end:
  8816. //json_object_put(obj); --- remove temporally
  8817. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8818. return result;
  8819. }
  8820. static char UpdateFirmwarepayloadData[300]={0};
  8821. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8822. {
  8823. mtrace();
  8824. int result = FAIL;
  8825. pthread_t t;
  8826. sendUpdateFirmwareConfirmation(uuid);
  8827. memset(UpdateFirmwarepayloadData, 0, 300);
  8828. strcpy(UpdateFirmwarepayloadData, payload);
  8829. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8830. ////pthread_join(t, NULL); //
  8831. //pthread_detach(t);
  8832. //sendUpdateFirmwareConfirmation(uuid);
  8833. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8834. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8835. return result;
  8836. }
  8837. void *UpdateFirmwareProcess(void *data)
  8838. {
  8839. pthread_detach(pthread_self());
  8840. mtrace();
  8841. int retriesInt =0, retryIntervalInt=0;
  8842. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8843. int port=0;
  8844. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8845. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8846. //char comfirmstr[20];
  8847. int isSuccess = 0;
  8848. char ftpbuf[200];
  8849. char temp[100];
  8850. char * pch;
  8851. int retriesISNULL=FALSE;
  8852. int retryInterval=FALSE;
  8853. int c = 0;
  8854. //int i = 0;
  8855. char *loc;
  8856. char sstr[300]={ 0 };
  8857. char str[300]={ 0 };
  8858. //char *str = (char*) data; // ? ?輸入資 ?
  8859. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8860. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8861. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8862. //***************location **************/
  8863. loc = strstr(str, "location");
  8864. memset(sstr ,0, sizeof(sstr) );
  8865. c = 0;
  8866. while (loc[3+strlen("location")+c] != '\"')
  8867. {
  8868. sstr[c] = loc[3+strlen("location")+c];
  8869. c++;
  8870. }
  8871. sstr[c] = '\0';
  8872. strcpy(locationstr, sstr);
  8873. //***************retries**************/
  8874. c = 0;
  8875. loc = strstr(str, "retries");
  8876. if(loc == NULL)
  8877. {
  8878. retriesISNULL=TRUE;
  8879. }
  8880. else
  8881. {
  8882. memset(sstr ,0, sizeof(sstr) );
  8883. while (loc[strlen("retries")+2+c] != ',')
  8884. {
  8885. sstr[c] = loc[strlen("retries")+2+c];
  8886. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8887. c++;
  8888. }
  8889. sstr[c] = '\0';
  8890. }
  8891. if(retriesISNULL == FALSE)
  8892. {
  8893. retriesInt = atoi(sstr);
  8894. }
  8895. //***************retrieveDate **************/
  8896. loc = strstr(str, "retrieveDate");
  8897. memset(sstr ,0, sizeof(sstr) );
  8898. c = 0;
  8899. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8900. {
  8901. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8902. c++;
  8903. }
  8904. sstr[c] = '\0';
  8905. strcpy(retrieveDatestr, sstr);
  8906. //***************retryInterval **************/
  8907. c = 0;
  8908. loc = strstr(str, "retryInterval");
  8909. memset(sstr ,0, sizeof(sstr) );
  8910. if(loc == NULL)
  8911. {
  8912. retryInterval=TRUE;
  8913. }
  8914. else
  8915. {
  8916. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8917. {
  8918. sstr[c] = loc[strlen("retryInterval")+2+c];
  8919. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8920. c++;
  8921. }
  8922. sstr[c] = '\0';
  8923. }
  8924. if(retryInterval==FALSE)
  8925. {
  8926. retryIntervalInt = atoi(sstr);
  8927. }
  8928. memset(ftppath, 0, sizeof(ftppath));
  8929. memset(path, 0, sizeof(path));
  8930. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8931. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8932. if(strncmp(locationstr,"http", 4) == 0)
  8933. {
  8934. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8935. protocol, host, path);
  8936. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8937. // protocol, user, password, host, path);
  8938. sprintf(ftppath,"/%s", path);
  8939. //DEBUG_INFO("protocol =%s\n",protocol);
  8940. //DEBUG_INFO("host =%s\n",host);
  8941. //DEBUG_INFO("path =%s\n",path);
  8942. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8943. int ftppathlen=strlen(ftppath);
  8944. int i=1;
  8945. char filenametemp[50];
  8946. while(i < ftppathlen)
  8947. {
  8948. int len=ftppathlen-i;
  8949. if(ftppath[len]== 47) // '/' ascll code: 47
  8950. {
  8951. DEBUG_INFO("compare '/' all right\n");
  8952. break;
  8953. }
  8954. i=i+1;
  8955. }
  8956. memset(filenametemp, 0, sizeof(filenametemp));
  8957. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8958. filenametemp[i+1] = 0;
  8959. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8960. do{
  8961. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8962. sleep(retryIntervalInt);
  8963. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8964. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8965. if(!isSuccess)
  8966. {
  8967. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8968. }
  8969. else
  8970. {
  8971. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8972. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8973. isUpdateRequest = TRUE;
  8974. }
  8975. }
  8976. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8977. {
  8978. memset(ftpbuf, 0, sizeof(ftpbuf));
  8979. memset(temp, 0, sizeof(temp));
  8980. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8981. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8982. int ftppathlen=strlen(ftpbuf);
  8983. int i=1;
  8984. char filenametemp[50];
  8985. while(i < ftppathlen)
  8986. {
  8987. int len=ftppathlen-i;
  8988. if(ftpbuf[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, ftpbuf+(ftppathlen-i+1), i+1);
  8997. filenametemp[i+1] = 0;
  8998. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8999. pch=strchr(temp,'@');
  9000. if(pch==NULL)
  9001. {
  9002. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9003. protocol, host, &port, path);
  9004. strcpy(user,"anonymous");
  9005. strcpy(password,"");
  9006. }
  9007. else
  9008. {
  9009. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9010. protocol, user, password, host, &port, path);
  9011. }
  9012. sscanf(host,"%[^/]%s",host1, path1);
  9013. sprintf(ftppath,"%s", path1);
  9014. //DEBUG_INFO("protocol =%s\n",protocol);
  9015. //DEBUG_INFO("user =%s\n",user);
  9016. //DEBUG_INFO("password =%s\n",password);
  9017. //DEBUG_INFO("host1 =%s\n",host1);
  9018. //DEBUG_INFO("port =%d\n",port);
  9019. //DEBUG_INFO("path1 =%s\n",path1);
  9020. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9021. //ftpFile(host, user, password, port, ftppath, fname);
  9022. //download firmware pthred
  9023. if(port == 0)
  9024. {
  9025. port = 21;
  9026. }
  9027. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9028. do{
  9029. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9030. sleep(retryIntervalInt);
  9031. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9032. if(!isSuccess)
  9033. {
  9034. //BulldogUtil.sleepMs(interval*1000);
  9035. DEBUG_INFO("Update firmware request and download file fail.\n");
  9036. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9037. }
  9038. else
  9039. {
  9040. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9041. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9042. isUpdateRequest = TRUE;
  9043. }
  9044. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9045. }
  9046. else
  9047. {
  9048. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9049. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9050. }
  9051. pthread_exit(NULL);
  9052. }
  9053. //==========================================
  9054. // Handle server response routine
  9055. //==========================================
  9056. void handleAuthorizeResponse(char *payload, int gun_index)
  9057. {
  9058. mtrace();
  9059. char expiryDatestr[30]={0};
  9060. char parentIdTagstr[20]={0};
  9061. char statusstr[20]={0};
  9062. char expiryDatestrtemp[30]={0};
  9063. char parentIdTagstrtemp[20]={0};
  9064. char IdTagstrtemp[20]={0};
  9065. char statusstrtemp[20]={0};
  9066. int expiryDateISNULL=FALSE;
  9067. int parentIdTagISNULL=FALSE;
  9068. char sstr[160]={ 0 };
  9069. char* filename = AuthorizationCache_JSON;
  9070. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9071. int c = 0;
  9072. char *loc;
  9073. int resultRename=0;
  9074. int responseIdTagInfoAsZero= 0;
  9075. char rmFileCmd[50]={0};
  9076. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9077. //***********expiryDate*************/
  9078. loc = strstr(payload, "expiryDate");
  9079. memset(sstr ,0, sizeof(sstr) );
  9080. c = 0;
  9081. if(loc == NULL)
  9082. {
  9083. expiryDateISNULL = TRUE;
  9084. }
  9085. else
  9086. {
  9087. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9088. {
  9089. sstr[c] = loc[3+strlen("expiryDate")+c];
  9090. c++;
  9091. }
  9092. sstr[c] = '\0';
  9093. strcpy(expiryDatestr, sstr);
  9094. }
  9095. //***********parentIdTag*************/
  9096. loc = strstr(payload, "parentIdTag");
  9097. memset(sstr ,0, sizeof(sstr) );
  9098. c = 0;
  9099. if(loc == NULL)
  9100. {
  9101. parentIdTagISNULL = TRUE;
  9102. }
  9103. else
  9104. {
  9105. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9106. {
  9107. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9108. c++;
  9109. }
  9110. sstr[c] = '\0';
  9111. strcpy(parentIdTagstr, sstr);
  9112. }
  9113. //***********status*************/
  9114. loc = strstr(payload, "status");
  9115. memset(sstr ,0, sizeof(sstr) );
  9116. c = 0;
  9117. while (loc[3+strlen("status")+c] != '\"')
  9118. {
  9119. sstr[c] = loc[3+strlen("status")+c];
  9120. c++;
  9121. }
  9122. sstr[c] = '\0';
  9123. strcpy(statusstr, sstr);
  9124. if(expiryDateISNULL == FALSE)
  9125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9126. if(parentIdTagISNULL == FALSE)
  9127. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9128. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9129. //Update idTag information to authorization cache if supproted
  9130. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9131. {
  9132. if((access(filename,F_OK))!=-1)
  9133. {
  9134. printf("AuthorizationCache exist.\n");
  9135. }
  9136. else
  9137. {
  9138. printf("AuthorizationCache not exist\n");
  9139. FILE *log = fopen(filename, "w+");
  9140. if(log == NULL)
  9141. {
  9142. printf("log is NULL\n");
  9143. goto out;
  9144. }
  9145. else
  9146. {
  9147. fclose(log);
  9148. }
  9149. }
  9150. FILE *infile;
  9151. FILE *outfile;
  9152. // open file for writing
  9153. infile = fopen (filename, "r");
  9154. outfile = fopen (tempfile, "w");
  9155. //*检测到文件结束标识返回1,否则返回0。*/
  9156. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9157. int c;
  9158. c = fgetc(infile);
  9159. //DEBUG_INFO("c:%d\n",c);
  9160. rewind(infile);
  9161. if(c == EOF)
  9162. {
  9163. DEBUG_INFO("Orignal File is NULL\n");
  9164. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9165. {
  9166. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9167. }
  9168. else
  9169. {
  9170. strcpy(expiryDatestrtemp, "");
  9171. }
  9172. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9173. {
  9174. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9175. }
  9176. else
  9177. {
  9178. //write Authorize IdTag
  9179. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9180. }
  9181. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9182. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9183. fclose(infile);
  9184. fclose(outfile);
  9185. sprintf(rmFileCmd,"rm -f %s",filename);
  9186. system(rmFileCmd);
  9187. resultRename = rename(tempfile, filename);
  9188. if(resultRename == 0)
  9189. {
  9190. printf("File renamed successfully");
  9191. }
  9192. else
  9193. {
  9194. printf("Error: unable to rename the file");
  9195. }
  9196. }
  9197. else
  9198. {
  9199. char buf[160]={0};
  9200. while (fgets(buf, sizeof(buf), infile) != NULL)
  9201. {
  9202. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9203. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9204. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9205. memset(statusstr, 0, sizeof(statusstrtemp));
  9206. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9207. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9208. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9209. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9210. //------------------IdTag-----------------------
  9211. loc = strstr(buf, "idTag");
  9212. memset(sstr ,0, sizeof(sstr) );
  9213. c = 0;
  9214. while (loc[3+strlen("idTag")+c] != '\"')
  9215. {
  9216. sstr[c] = loc[3+strlen("idTag")+c];
  9217. c++;
  9218. }
  9219. sstr[c] = '\0';
  9220. strcpy(IdTagstrtemp,sstr);
  9221. //*********************expiryDate***************/
  9222. loc = strstr(buf, "expiryDate");
  9223. memset(sstr ,0, sizeof(sstr) );
  9224. c = 0;
  9225. while (loc[3+strlen("expiryDate")+c] != '\"')
  9226. {
  9227. sstr[c] = loc[3+strlen("expiryDate")+c];
  9228. c++;
  9229. }
  9230. sstr[c] = '\0';
  9231. strcpy(expiryDatestr,sstr);
  9232. //*********************parentIdTag***************/
  9233. loc = strstr(buf, "parentIdTag");
  9234. memset(sstr ,0, sizeof(sstr) );
  9235. c = 0;
  9236. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9237. {
  9238. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9239. c++;
  9240. }
  9241. sstr[c] = '\0';
  9242. strcpy(parentIdTagstr,sstr);
  9243. //*********************status***************/
  9244. loc = strstr(buf, "status");
  9245. memset(sstr ,0, sizeof(sstr) );
  9246. c = 0;
  9247. while (loc[3+strlen("status")+c] != '\"')
  9248. {
  9249. sstr[c] = loc[3+strlen("status")+c];
  9250. c++;
  9251. }
  9252. sstr[c] = '\0';
  9253. strcpy(statusstr,sstr);
  9254. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9255. {
  9256. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9257. responseIdTagInfoAsZero = 1;
  9258. }
  9259. else
  9260. {
  9261. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9262. }
  9263. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9264. {
  9265. //modify item
  9266. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9267. {
  9268. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9269. }
  9270. else
  9271. {
  9272. strcpy(expiryDatestrtemp, "");
  9273. }
  9274. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9275. {
  9276. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9277. }
  9278. else
  9279. {
  9280. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9281. }
  9282. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9283. }
  9284. else
  9285. {
  9286. //wrie original item
  9287. strcpy(expiryDatestrtemp, expiryDatestr);
  9288. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9289. strcpy(statusstrtemp, statusstr);
  9290. }
  9291. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9292. }
  9293. fclose(infile);
  9294. fclose(outfile);
  9295. sprintf(rmFileCmd,"rm -f %s",filename);
  9296. system(rmFileCmd);
  9297. resultRename = rename(tempfile, filename);
  9298. if(resultRename == 0)
  9299. {
  9300. DEBUG_INFO("File renamed successfully");
  9301. }
  9302. else
  9303. {
  9304. DEBUG_INFO("Error: unable to rename the file");
  9305. }
  9306. }
  9307. }
  9308. out:
  9309. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9310. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9311. authorizeRetryTimes = 0;
  9312. }
  9313. void handleBootNotificationResponse(char *payload, int gun_index)
  9314. {
  9315. mtrace();
  9316. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9317. char statusStr[12]={0};
  9318. char currentTimeStr[30]={0};
  9319. char *loc;
  9320. int intervalInt = 0;
  9321. int c = 0;
  9322. //double diff_t;
  9323. struct tm tp;
  9324. char buf[28]={0};
  9325. char timebuf[50]={0};
  9326. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9327. //*** interval ****/
  9328. c = 0;
  9329. loc = strstr(payload, "interval");
  9330. //printf("loc=%s\n",loc);
  9331. memset(sstr ,0, sizeof(sstr) );
  9332. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9333. {
  9334. sstr[c] = loc[strlen("interval")+2+c];
  9335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9336. c++;
  9337. }
  9338. sstr[c] = '\0';
  9339. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9340. intervalInt = atoi(sstr);
  9341. //***status ****/
  9342. loc = strstr(payload, "status");
  9343. memset(sstr ,0, sizeof(sstr) );
  9344. c = 0;
  9345. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9346. {
  9347. sstr[c] = loc[3+strlen("status")+c];
  9348. c++;
  9349. }
  9350. sstr[c] = '\0';
  9351. strcpy(statusStr, sstr);
  9352. //***currentTime ****/
  9353. loc = strstr(payload, "currentTime");
  9354. //printf("loc=%s\n",loc);
  9355. memset(sstr ,0, sizeof(sstr) );
  9356. c = 0;
  9357. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9358. {
  9359. sstr[c] = loc[3+strlen("currentTime")+c];
  9360. c++;
  9361. }
  9362. sstr[c] = '\0';
  9363. strcpy(currentTimeStr, sstr);
  9364. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9365. HeartBeatWaitTime = BootNotificationInterval;
  9366. clientTime.Heartbeat=time((time_t*)NULL);
  9367. //write back to ShmOCPP16Data->BootNotification
  9368. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9369. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9370. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9371. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9372. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9373. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9374. {
  9375. server_sign = TRUE;
  9376. server_pending =FALSE;
  9377. }
  9378. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9379. {
  9380. server_pending = TRUE;
  9381. }
  9382. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9383. tp.tm_isdst = -1;
  9384. //time_t utc = mktime(&tp);
  9385. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9386. memset(timebuf, 0, sizeof timebuf);
  9387. sprintf(timebuf,"date -s '%s'",buf);
  9388. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9389. system(timebuf);
  9390. //==============================================
  9391. // RTC sync
  9392. //==============================================
  9393. system("/sbin/hwclock -w --systohc");
  9394. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9395. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9396. }
  9397. void handleDataTransferResponse(char *payload, int gun_index)
  9398. {
  9399. char sstr[160]={0};//sstr[200]={ 0 };
  9400. int c = 0;
  9401. char *loc;
  9402. DEBUG_INFO("handleDataTransferResponse ...\n");
  9403. loc = strstr(payload, "status");
  9404. printf("loc=%s\n",loc);
  9405. c = 0;
  9406. while (loc[3+strlen("status")+c] != '\"')
  9407. {
  9408. sstr[c] = loc[3+strlen("status")+c];
  9409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9410. c++;
  9411. }
  9412. sstr[c] = '\0';
  9413. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9414. }
  9415. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9416. {
  9417. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9418. //struct json_object *obj;
  9419. // obj = json_tokener_parse(payload);
  9420. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9421. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9422. //No fields are defined.
  9423. }
  9424. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9425. {
  9426. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9427. //struct json_object *obj;
  9428. // obj = json_tokener_parse(payload);
  9429. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9430. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9431. //No fields are defined.
  9432. }
  9433. void handleHeartbeatResponse(char *payload, int gun_index)
  9434. {
  9435. mtrace();
  9436. //double diff_t;
  9437. struct tm tp;
  9438. char buf[28]={0};
  9439. char timebuf[50]={0};
  9440. char sstr[30]={ 0 };
  9441. int c = 0;
  9442. char *loc;
  9443. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9444. c = 0;
  9445. loc = strstr(payload, "currentTime");
  9446. memset(sstr ,0, sizeof(sstr) );
  9447. while (loc[3+strlen("currentTime")+c] != '\"')
  9448. {
  9449. sstr[c] = loc[3+strlen("currentTime")+c];
  9450. c++;
  9451. }
  9452. sstr[c] = '\0';
  9453. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9454. // #ifdef SystemLogMessage
  9455. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9456. // #endif
  9457. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9458. tp.tm_isdst = -1;
  9459. //time_t utc = mktime(&tp);
  9460. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9461. memset(timebuf, 0, sizeof timebuf);
  9462. sprintf(timebuf,"date -s '%s'",buf);
  9463. system(timebuf);
  9464. //==============================================
  9465. // RTC sync
  9466. //==============================================
  9467. system("/sbin/hwclock -w --systohc");
  9468. if(FirstHeartBeat == 0)
  9469. {
  9470. FirstHeartBeat = 1;
  9471. }
  9472. HeartBeatWithNOResponse = 0;
  9473. //--------Print Out HeartBeat log
  9474. {
  9475. double diff_t;
  9476. struct tm tp,tp1;
  9477. // BootNotification Receive Time
  9478. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9479. tp.tm_isdst = -1;
  9480. time_t BootNotificationReceiveTime = mktime(&tp);
  9481. //HeartBeat Receive Time
  9482. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9483. tp1.tm_isdst = -1;
  9484. time_t HeartBeatReceiveTime = mktime(&tp1);
  9485. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9486. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9487. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9488. {
  9489. HeartBeatCountPerHour = (int)diff_t / 3600;
  9490. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9491. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9492. }
  9493. }
  9494. }
  9495. void handleMeterValuesResponse(char *payload, int gun_index)
  9496. {
  9497. mtrace();
  9498. //struct json_object *obj;
  9499. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9500. //No fields are defined.
  9501. }
  9502. void handleStartTransactionResponse(char *payload, int gun_index)
  9503. {
  9504. mtrace();
  9505. char sstr[28]={ 0 };
  9506. int c = 0;
  9507. char *loc;
  9508. int transactionIdInt = 0;
  9509. FILE *outfile;
  9510. char data[100]={0};
  9511. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9512. DEBUG_INFO("handleStartTransactionResponse\n");
  9513. //****************expiryDate********************/
  9514. loc = strstr(payload, "expiryDate");
  9515. if(loc == NULL)
  9516. {
  9517. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9518. }
  9519. else
  9520. {
  9521. c = 0;
  9522. memset(sstr ,0, sizeof(sstr) );
  9523. while (loc[3+strlen("expiryDate")+c] != '\"')
  9524. {
  9525. sstr[c] = loc[3+strlen("expiryDate")+c];
  9526. c++;
  9527. }
  9528. sstr[c] = '\0';
  9529. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9530. }
  9531. //****************parentIdTag********************/
  9532. loc = strstr(payload, "parentIdTag");
  9533. if(loc == NULL)
  9534. {
  9535. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9536. }
  9537. else
  9538. {
  9539. c = 0;
  9540. memset(sstr ,0, sizeof(sstr) );
  9541. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9542. {
  9543. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9544. c++;
  9545. }
  9546. sstr[c] = '\0';
  9547. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9548. }
  9549. //****************status********************/
  9550. loc = strstr(payload, "status");
  9551. if(loc == NULL)
  9552. {
  9553. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9554. }
  9555. else
  9556. {
  9557. c = 0;
  9558. memset(sstr ,0, sizeof(sstr) );
  9559. while (loc[3+strlen("status")+c] != '\"')
  9560. {
  9561. sstr[c] = loc[3+strlen("status")+c];
  9562. c++;
  9563. }
  9564. sstr[c] = '\0';
  9565. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9566. }
  9567. //****************transactionId********************/
  9568. c=0;
  9569. loc = strstr(payload, "transactionId");
  9570. memset(sstr ,0, sizeof(sstr) );
  9571. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9572. {
  9573. sstr[c] = loc[strlen("transactionId")+2+c];
  9574. c++;
  9575. }
  9576. sstr[c] = '\0';
  9577. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9578. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9579. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9580. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9581. //-----------Start : write to the Queue TransactionId file -----------------//
  9582. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9583. {
  9584. //DEBUG_INFO("QueueTransactionId exist.\n");
  9585. }
  9586. else
  9587. {
  9588. //DEBUG_INFO("QueueTransactionId not exist\n");
  9589. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9590. if(log == NULL)
  9591. {
  9592. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9593. return ;
  9594. }
  9595. else
  9596. {
  9597. fclose(log);
  9598. }
  9599. }
  9600. // open file for writing
  9601. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9602. //DEBUG_INFO("data=%s\n",data);
  9603. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9604. fputs(data, outfile);
  9605. //fputs("\n", outfile);
  9606. fclose (outfile);
  9607. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9608. TransactionId[gun_index] = transactionIdInt;
  9609. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9610. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9611. #ifdef SystemLogMessage
  9612. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9613. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9614. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9615. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9616. #endif
  9617. }
  9618. void handleStatusNotificationResponse(char *payload, int gun_index)
  9619. {
  9620. mtrace();
  9621. printf("handleStatusNotificationResponse\n");
  9622. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9623. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9624. }
  9625. void handleStopTransactionnResponse(char *payload, int gun_index)
  9626. {
  9627. mtrace();
  9628. char sstr[30]={ 0 };
  9629. int c = 0;
  9630. char *loc;
  9631. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9632. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9633. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9634. loc = strstr(payload, "idTagInfo");
  9635. //***********************idTagInfo************************/
  9636. if(loc != NULL)
  9637. {
  9638. //***********************expiryDate************************/
  9639. loc = strstr(payload, "expiryDate");
  9640. if(loc != NULL)
  9641. {
  9642. memset(sstr ,0, sizeof(sstr) );
  9643. c = 0;
  9644. while (loc[3+strlen("expiryDate")+c] != '\"')
  9645. {
  9646. sstr[c] = loc[3+strlen("expiryDate")+c];
  9647. c++;
  9648. }
  9649. sstr[c] = '\0';
  9650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9651. }
  9652. //***********************parentIdTag************************/
  9653. loc = strstr(payload, "parentIdTag");
  9654. if(loc != NULL)
  9655. {
  9656. memset(sstr ,0, sizeof(sstr) );
  9657. c = 0;
  9658. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9659. {
  9660. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9661. c++;
  9662. }
  9663. sstr[c] = '\0';
  9664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9665. }
  9666. //***********************status************************/
  9667. loc = strstr(payload, "status");
  9668. memset(sstr ,0, sizeof(sstr) );
  9669. c = 0;
  9670. while (loc[3+strlen("status")+c] != '\"')
  9671. {
  9672. sstr[c] = loc[3+strlen("status")+c];
  9673. c++;
  9674. }
  9675. sstr[c] = '\0';
  9676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9677. }
  9678. #ifdef SystemLogMessage
  9679. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9680. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9681. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9682. #endif
  9683. }
  9684. //==========================================
  9685. // Handle Error routine
  9686. //==========================================
  9687. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9688. {
  9689. mtrace();
  9690. #ifdef SystemLogMessage
  9691. DEBUG_INFO("errorCode: %s\n", errorCode);
  9692. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9693. DEBUG_INFO("errorDetails: %s\n", payload);
  9694. #endif
  9695. }
  9696. //===============================================
  9697. // Common routine
  9698. //===============================================
  9699. int initialConfigurationTable(void)
  9700. {
  9701. //clock_t start_t, end_t, total_t;
  9702. FILE *fp;
  9703. FILE *outfile;
  9704. char str[200]={0};
  9705. char sstr[100]={0};
  9706. int c = 0;
  9707. char *loc;
  9708. printf("initialConfigurationTable \n");
  9709. //start_t = clock();
  9710. //printf("Starting of the program, start_t = %ld\n", start_t);
  9711. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9712. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9713. {
  9714. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9715. if(outfile == NULL) {
  9716. DEBUG_INFO("Error opening file");
  9717. return FALSE;
  9718. }
  9719. /*Core Profile*/
  9720. //AllowOfflineTxForUnknownId
  9721. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 0;
  9722. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", "FALSE");
  9726. //AuthorizationCacheEnabled
  9727. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9731. //AuthorizeRemoteTxRequests
  9732. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9736. //BlinkRepeat
  9737. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9741. //ClockAlignedDataInterval
  9742. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9746. //ConnectionTimeOut
  9747. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9751. //GetConfigurationMaxKeys
  9752. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9756. // HeartbeatInterval
  9757. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9761. // LightIntensity
  9762. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9766. // LocalAuthorizeOffline
  9767. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9771. // LocalPreAuthorize
  9772. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9776. // MaxEnergyOnInvalidId
  9777. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9780. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9782. // MeterValuesAlignedData
  9783. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9787. // MeterValuesAlignedDataMaxLength
  9788. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9792. // MeterValuesSampledData
  9793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9797. // MeterValuesSampledDataMaxLength
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9802. // MeterValueSampleInterval
  9803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9807. // MinimumStatusDuration
  9808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9811. server_cycle_Status = 120; //StatusNotification cycle
  9812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9813. // NumberOfConnectors
  9814. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9817. {
  9818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9819. }
  9820. else
  9821. {
  9822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9823. }
  9824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9825. // ResetRetries
  9826. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9830. // ConnectorPhaseRotation
  9831. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9835. // ConnectorPhaseRotationMaxLength
  9836. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9840. // StopTransactionOnEVSideDisconnect
  9841. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9845. // StopTransactionOnInvalidId
  9846. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9850. // StopTxnAlignedData
  9851. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  9855. // StopTxnAlignedDataMaxLength
  9856. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9860. // StopTxnSampledData
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9865. // StopTxnSampledDataMaxLength
  9866. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9869. {
  9870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9871. }
  9872. else
  9873. {
  9874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9875. }
  9876. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9878. // SupportedFeatureProfiles
  9879. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9883. // SupportedFeatureProfilesMaxLength
  9884. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9888. // TransactionMessageAttempts
  9889. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9892. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9894. // TransactionMessageRetryInterval
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9898. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9900. // UnlockConnectorOnEVSideDisconnect
  9901. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9905. // WebSocketPingInterval
  9906. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9910. //* Local Auth List Management Profile*/
  9911. #if 0
  9912. //For OCTT Test Case
  9913. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9916. #endif
  9917. #if 1
  9918. //LocalAuthListEnabled
  9919. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9923. #endif
  9924. //LocalAuthListMaxLength
  9925. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9929. //SendLocalListMaxLength
  9930. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9934. //ReserveConnectorZeroSupported
  9935. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9939. //* Smart Charging Profile */
  9940. //ChargeProfileMaxStackLevel
  9941. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9945. // ChargingScheduleAllowedChargingRateUnit
  9946. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9950. // ChargingScheduleMaxPeriods
  9951. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9955. // ConnectorSwitch3to1PhaseSupported
  9956. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9960. // MaxChargingProfilesInstalled
  9961. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9965. fclose(outfile);
  9966. }
  9967. else
  9968. {
  9969. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9970. char keystr[60]={0};
  9971. char readonlystr[10]={0};
  9972. char valuestr[100]={0};
  9973. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9974. if(fp == NULL) {
  9975. DEBUG_INFO("Error opening file");
  9976. return FALSE;
  9977. }
  9978. while( fgets (str, sizeof(str), fp)!=NULL )
  9979. {
  9980. //DEBUG_INFO("Get Configuration \n");
  9981. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9982. //*************************key*********************************/
  9983. loc = strstr(str, "key");
  9984. c = 0;
  9985. memset(sstr ,0, sizeof(sstr) );
  9986. while (loc[strlen("key")+3+c] != '\"')
  9987. {
  9988. sstr[c] = loc[strlen("key")+3+c];
  9989. c++;
  9990. }
  9991. sstr[c] = '\0';
  9992. strcpy(keystr,sstr);
  9993. //*************************readonly*********************************/
  9994. loc = strstr(str, "readonly");
  9995. c = 0;
  9996. memset(sstr ,0, sizeof(sstr) );
  9997. while (loc[strlen("readonly")+2+c] != ',')
  9998. {
  9999. sstr[c] = loc[strlen("readonly")+2+c];
  10000. c++;
  10001. }
  10002. sstr[c] = '\0';
  10003. strcpy(readonlystr,sstr);
  10004. //*************************value*********************************/
  10005. loc = strstr(str, "value");
  10006. c = 0;
  10007. memset(sstr ,0, sizeof(sstr) );
  10008. while (loc[strlen("value")+3+c] != '\"')
  10009. {
  10010. sstr[c] = loc[strlen("value")+3+c];
  10011. c++;
  10012. }
  10013. sstr[c] = '\0';
  10014. strcpy(valuestr,sstr);
  10015. // DEBUG_INFO("keystr=%s\n",keystr);
  10016. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10017. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10018. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10019. {
  10020. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10021. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10023. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10024. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10025. }
  10026. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10027. {
  10028. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10029. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10031. }
  10032. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10033. {
  10034. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10036. }
  10037. if(strcmp(keystr, "BlinkRepeat") == 0)
  10038. {
  10039. //Charger.BlinkRepeat = Integer.parseInt(value);
  10040. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10042. }
  10043. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10044. {
  10045. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10047. }
  10048. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10049. {
  10050. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10052. }
  10053. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10054. {
  10055. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10057. }
  10058. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10059. {
  10060. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10062. HeartBeatWaitTime = atoi(valuestr);
  10063. }
  10064. if(strcmp(keystr, "LightIntensity") == 0)
  10065. {
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10068. }
  10069. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10070. {
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10073. }
  10074. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10075. {
  10076. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10078. }
  10079. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10080. {
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10083. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10084. }
  10085. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10086. {
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10089. }
  10090. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10091. {
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10094. }
  10095. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10096. {
  10097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10099. }
  10100. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10101. {
  10102. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10104. }
  10105. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10106. {
  10107. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10109. }
  10110. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10111. {
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10114. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10115. }
  10116. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10117. {
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10120. }
  10121. if(strcmp(keystr, "ResetRetries") == 0)
  10122. {
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10125. }
  10126. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10127. {
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10130. }
  10131. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10132. {
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10135. }
  10136. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10137. {
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10140. }
  10141. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10142. {
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10145. }
  10146. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10147. {
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10150. }
  10151. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10152. {
  10153. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10155. }
  10156. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10157. {
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10160. }
  10161. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10162. {
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10165. }
  10166. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10167. {
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10170. }
  10171. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10172. {
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10175. }
  10176. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10177. {
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10180. TransactionMessageAttemptsValue = atoi(valuestr);
  10181. }
  10182. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10183. {
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10186. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10187. }
  10188. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10189. {
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10192. }
  10193. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10194. {
  10195. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10197. }
  10198. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10199. {
  10200. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10202. }
  10203. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10204. {
  10205. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10207. }
  10208. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10209. {
  10210. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10212. }
  10213. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10214. {
  10215. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10217. }
  10218. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10219. {
  10220. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10222. }
  10223. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10224. {
  10225. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10227. }
  10228. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10229. {
  10230. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10232. }
  10233. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10234. {
  10235. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10237. }
  10238. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10239. {
  10240. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10242. }
  10243. }
  10244. fclose(fp);
  10245. }
  10246. //end_t = clock();
  10247. //printf("End of the big loop, end_t = %ld\n", end_t);
  10248. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10249. //printf("Total time taken by CPU: %f\n", total_t );
  10250. return 0;
  10251. }
  10252. void StoreConfigurationTable(void)
  10253. {
  10254. FILE *outfile;
  10255. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10256. if(outfile == NULL)
  10257. {
  10258. DEBUG_INFO("Error opening file");
  10259. return ;
  10260. }
  10261. /*Core Profile*/
  10262. //AllowOfflineTxForUnknownId
  10263. /*
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10265. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10268. */
  10269. //DEBUG_INFO("data=%s\n",data);
  10270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10271. //AuthorizationCacheEnabled
  10272. /*
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10276. */
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10278. //AuthorizeRemoteTxRequests
  10279. /*
  10280. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10283. */
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10285. //BlinkRepeat
  10286. /*
  10287. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10290. */
  10291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10292. //ClockAlignedDataInterval
  10293. /*
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10297. */
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10299. //ConnectionTimeOut
  10300. /*
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10304. */
  10305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10306. //GetConfigurationMaxKeys
  10307. /*
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10311. */
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10313. // HeartbeatInterval
  10314. /*
  10315. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10318. */
  10319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10320. // LightIntensity
  10321. /*
  10322. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10325. */
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10327. // LocalAuthorizeOffline
  10328. /*
  10329. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10332. */
  10333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10334. // LocalPreAuthorize
  10335. /*
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10339. */
  10340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10341. // MaxEnergyOnInvalidId
  10342. /*
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10346. */
  10347. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10349. // MeterValuesAlignedData
  10350. /*
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10354. */
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10356. // MeterValuesAlignedDataMaxLength
  10357. /*
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10361. */
  10362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10363. // MeterValuesSampledData
  10364. /*
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10368. */
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10370. // MeterValuesSampledDataMaxLength
  10371. /*
  10372. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10375. */
  10376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10377. // MeterValueSampleInterval
  10378. /*
  10379. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10382. */
  10383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10384. // MinimumStatusDuration
  10385. /*
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10389. */
  10390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10391. // NumberOfConnectors
  10392. /*
  10393. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10396. {
  10397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10398. }
  10399. else
  10400. {
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10402. }
  10403. */
  10404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10405. // ResetRetries
  10406. /*
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10410. */
  10411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10412. // ConnectorPhaseRotation
  10413. /*
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10417. */
  10418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10419. // ConnectorPhaseRotationMaxLength
  10420. /*
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10424. */
  10425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10426. // StopTransactionOnEVSideDisconnect
  10427. /*
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10431. */
  10432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10433. // StopTransactionOnInvalidId
  10434. /*
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10438. */
  10439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10440. // StopTxnAlignedData
  10441. /*
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10445. */
  10446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10447. // StopTxnAlignedDataMaxLength
  10448. /*
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10452. */
  10453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10454. // StopTxnSampledData
  10455. /*
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10459. */
  10460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10461. // StopTxnSampledDataMaxLength
  10462. /*
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10466. */
  10467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10468. // SupportedFeatureProfiles
  10469. /*
  10470. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10473. */
  10474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10475. // SupportedFeatureProfilesMaxLength
  10476. /*
  10477. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10480. */
  10481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10482. // TransactionMessageAttempts
  10483. /*
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10487. */
  10488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10489. // TransactionMessageRetryInterval
  10490. /*
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10494. */
  10495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10496. // UnlockConnectorOnEVSideDisconnect
  10497. /*
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10501. */
  10502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10503. // WebSocketPingInterval
  10504. /*
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10508. */
  10509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10510. //* Local Auth List Management Profile*/
  10511. //LocalAuthListEnabled
  10512. /*
  10513. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10516. */
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10518. //LocalAuthListMaxLength
  10519. /*
  10520. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10523. */
  10524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10525. //SendLocalListMaxLength
  10526. /*
  10527. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10530. */
  10531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10532. //ReserveConnectorZeroSupported
  10533. /*
  10534. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10537. */
  10538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10539. //* Smart Charging Profile */
  10540. //ChargeProfileMaxStackLevel
  10541. /*
  10542. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10545. */
  10546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10547. // ChargingScheduleAllowedChargingRateUnit
  10548. /*
  10549. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10552. */
  10553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10554. // ChargingScheduleMaxPeriods
  10555. /*
  10556. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10559. */
  10560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10561. // ConnectorSwitch3to1PhaseSupported
  10562. /*
  10563. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10566. */
  10567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10568. // MaxChargingProfilesInstalled
  10569. /*
  10570. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10573. */
  10574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10575. fclose(outfile);
  10576. }
  10577. void getKeyValue(char *keyReq)
  10578. {
  10579. int isEmpty = FALSE;
  10580. int isKnowKey = FALSE;
  10581. //int unKnowIndex = 0;
  10582. DEBUG_INFO("getKeyValue \n");
  10583. DEBUG_INFO("keyReq=%s \n",keyReq);
  10584. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10585. isEmpty = TRUE;
  10586. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10587. {
  10588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10591. {
  10592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10593. }
  10594. else
  10595. {
  10596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10597. }
  10598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10599. isKnowKey = TRUE;
  10600. }
  10601. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10602. {
  10603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10606. {
  10607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10608. }
  10609. else
  10610. {
  10611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10612. }
  10613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10614. isKnowKey = TRUE;
  10615. }
  10616. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10617. {
  10618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10621. {
  10622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10623. }
  10624. else
  10625. {
  10626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10627. }
  10628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10629. isKnowKey = TRUE;
  10630. }
  10631. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10632. {
  10633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10636. {
  10637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10638. }
  10639. else
  10640. {
  10641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10642. }
  10643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10644. isKnowKey = TRUE;
  10645. }
  10646. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10647. {
  10648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10651. {
  10652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10653. }
  10654. else
  10655. {
  10656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10657. }
  10658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10659. isKnowKey = TRUE;
  10660. }
  10661. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10662. {
  10663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10666. {
  10667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10668. }
  10669. else
  10670. {
  10671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10672. }
  10673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10674. isKnowKey = TRUE;
  10675. }
  10676. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10677. {
  10678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10681. {
  10682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10683. }
  10684. else
  10685. {
  10686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10687. }
  10688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10689. isKnowKey = TRUE;
  10690. }
  10691. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10692. {
  10693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10696. {
  10697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10698. }
  10699. else
  10700. {
  10701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10702. }
  10703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10704. isKnowKey = TRUE;
  10705. }
  10706. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10707. {
  10708. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10711. {
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10713. }
  10714. else
  10715. {
  10716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10717. }
  10718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10719. isKnowKey = TRUE;
  10720. }
  10721. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10722. {
  10723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10726. {
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10728. }
  10729. else
  10730. {
  10731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10732. }
  10733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10734. isKnowKey = TRUE;
  10735. }
  10736. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10737. {
  10738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10741. {
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10743. }
  10744. else
  10745. {
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10747. }
  10748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10749. isKnowKey = TRUE;
  10750. }
  10751. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10752. {
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10756. {
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10758. }
  10759. else
  10760. {
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10762. }
  10763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10764. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10765. isKnowKey = TRUE;
  10766. }
  10767. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10774. }
  10775. else
  10776. {
  10777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10778. }
  10779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10780. isKnowKey = TRUE;
  10781. }
  10782. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10789. }
  10790. else
  10791. {
  10792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10793. }
  10794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10795. isKnowKey = TRUE;
  10796. }
  10797. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10804. }
  10805. else
  10806. {
  10807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10808. }
  10809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10810. isKnowKey = TRUE;
  10811. }
  10812. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10819. }
  10820. else
  10821. {
  10822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10823. }
  10824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10825. isKnowKey = TRUE;
  10826. }
  10827. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10834. }
  10835. else
  10836. {
  10837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10838. }
  10839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10840. isKnowKey = TRUE;
  10841. }
  10842. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10849. }
  10850. else
  10851. {
  10852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10853. }
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10855. isKnowKey = TRUE;
  10856. }
  10857. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10862. {
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10864. }
  10865. else
  10866. {
  10867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10868. }
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10870. isKnowKey = TRUE;
  10871. }
  10872. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10879. }
  10880. else
  10881. {
  10882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10883. }
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10885. isKnowKey = TRUE;
  10886. }
  10887. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10894. }
  10895. else
  10896. {
  10897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10898. }
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10900. isKnowKey = TRUE;
  10901. }
  10902. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10909. }
  10910. else
  10911. {
  10912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10913. }
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10915. isKnowKey = TRUE;
  10916. }
  10917. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10924. }
  10925. else
  10926. {
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10928. }
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10930. isKnowKey = TRUE;
  10931. }
  10932. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10939. }
  10940. else
  10941. {
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10943. }
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10945. isKnowKey = TRUE;
  10946. }
  10947. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10954. }
  10955. else
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10958. }
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10960. isKnowKey = TRUE;
  10961. }
  10962. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10969. }
  10970. else
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10973. }
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10975. isKnowKey = TRUE;
  10976. }
  10977. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10984. }
  10985. else
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10988. }
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10990. isKnowKey = TRUE;
  10991. }
  10992. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10999. }
  11000. else
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11003. }
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11005. isKnowKey = TRUE;
  11006. }
  11007. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11014. }
  11015. else
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11018. }
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11020. isKnowKey = TRUE;
  11021. }
  11022. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11029. }
  11030. else
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11033. }
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11035. isKnowKey = TRUE;
  11036. }
  11037. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11044. }
  11045. else
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11048. }
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11050. isKnowKey = TRUE;
  11051. }
  11052. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11059. }
  11060. else
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11063. }
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11065. isKnowKey = TRUE;
  11066. }
  11067. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11074. }
  11075. else
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11078. }
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11080. isKnowKey = TRUE;
  11081. }
  11082. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11089. }
  11090. else
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11093. }
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11095. isKnowKey = TRUE;
  11096. }
  11097. #if 0
  11098. //For OCTT Test Case
  11099. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11103. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11106. }
  11107. else
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11110. }
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11112. isKnowKey = TRUE;
  11113. }
  11114. #endif
  11115. #if 1
  11116. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11120. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11129. isKnowKey = TRUE;
  11130. }
  11131. #endif
  11132. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11136. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11139. }
  11140. else
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11143. }
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11145. isKnowKey = TRUE;
  11146. }
  11147. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11151. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11154. }
  11155. else
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11158. }
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11160. isKnowKey = TRUE;
  11161. }
  11162. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11166. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11169. }
  11170. else
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11173. }
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11175. isKnowKey = TRUE;
  11176. }
  11177. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11181. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11184. }
  11185. else
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11188. }
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11190. isKnowKey = TRUE;
  11191. }
  11192. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11196. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11199. }
  11200. else
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11203. }
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11205. isKnowKey = TRUE;
  11206. }
  11207. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11211. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11214. }
  11215. else
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11218. }
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11220. isKnowKey = TRUE;
  11221. }
  11222. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11226. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11229. }
  11230. else
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11233. }
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11235. isKnowKey = TRUE;
  11236. }
  11237. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11241. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11250. isKnowKey = TRUE;
  11251. }
  11252. //=========================================================
  11253. if(!isEmpty && !isKnowKey)
  11254. {
  11255. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11256. strcpy(unknownkey[UnknownKeynum], keyReq);
  11257. UnknownKeynum = UnknownKeynum + 1;
  11258. }
  11259. }
  11260. void processUnkownKey(void)
  11261. {
  11262. DEBUG_INFO("processUnkownKey\n");
  11263. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11264. for(int index=0; index < UnknownKeynum; index++)
  11265. {
  11266. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11267. {
  11268. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11269. }
  11270. }
  11271. }
  11272. int setKeyValue(char *key, char *value)
  11273. {
  11274. int isSuccess = NotSupported;
  11275. int check_ascii=0;
  11276. char str[10]={0};
  11277. #ifdef Debug
  11278. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11279. #endif
  11280. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11281. {
  11282. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11284. {
  11285. strcpy(str, (const char*)value);
  11286. for(int i = 0; str[i]; i++){
  11287. str[i] = tolower(str[i]);
  11288. }
  11289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11290. isSuccess = ConfigurationStatus_Accepted;
  11291. }
  11292. else
  11293. {
  11294. isSuccess = ConfigurationStatus_Rejected;
  11295. }
  11296. }
  11297. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11298. {
  11299. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11301. {
  11302. strcpy(str, (const char*)value);
  11303. for(int i = 0; str[i]; i++){
  11304. str[i] = tolower(str[i]);
  11305. }
  11306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11307. isSuccess = ConfigurationStatus_Accepted;
  11308. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11309. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11310. }
  11311. else
  11312. {
  11313. isSuccess = ConfigurationStatus_Rejected;
  11314. }
  11315. }
  11316. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11317. {
  11318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11319. {
  11320. strcpy(str, (const char*)value);
  11321. for(int i = 0; str[i]; i++)
  11322. {
  11323. str[i] = tolower(str[i]);
  11324. }
  11325. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11327. isSuccess = ConfigurationStatus_Accepted;
  11328. }
  11329. else
  11330. {
  11331. isSuccess = ConfigurationStatus_Rejected;
  11332. }
  11333. }
  11334. if(strcmp(key, "BlinkRepeat") == 0)
  11335. {
  11336. //Charger.BlinkRepeat = Integer.parseInt(value);
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11338. {
  11339. check_ascii = value[0];
  11340. if( (check_ascii < 48) || (check_ascii > 57) )
  11341. {
  11342. isSuccess = ConfigurationStatus_Rejected;
  11343. }
  11344. else
  11345. {
  11346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11347. isSuccess = ConfigurationStatus_Accepted;
  11348. }
  11349. }
  11350. else
  11351. {
  11352. isSuccess = ConfigurationStatus_Rejected;
  11353. }
  11354. }
  11355. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11356. {
  11357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11358. {
  11359. check_ascii = value[0];
  11360. if( (check_ascii < 48) || (check_ascii > 57) )
  11361. {
  11362. isSuccess = ConfigurationStatus_Rejected;
  11363. }
  11364. else
  11365. {
  11366. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11368. isSuccess = ConfigurationStatus_Accepted;
  11369. }
  11370. }
  11371. else
  11372. {
  11373. isSuccess = ConfigurationStatus_Rejected;
  11374. }
  11375. }
  11376. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11377. {
  11378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11379. {
  11380. check_ascii = value[0];
  11381. if( (check_ascii < 48) || (check_ascii > 57) )
  11382. {
  11383. isSuccess = ConfigurationStatus_Rejected;
  11384. }
  11385. else
  11386. {
  11387. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11389. isSuccess = ConfigurationStatus_Accepted;
  11390. }
  11391. }
  11392. else
  11393. {
  11394. isSuccess = ConfigurationStatus_Rejected;
  11395. }
  11396. }
  11397. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11398. {
  11399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11400. {
  11401. check_ascii = value[0];
  11402. if( (check_ascii < 48) || (check_ascii > 57) )
  11403. {
  11404. isSuccess = ConfigurationStatus_Rejected;
  11405. }
  11406. else
  11407. {
  11408. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11410. isSuccess = ConfigurationStatus_Accepted;
  11411. }
  11412. }
  11413. else
  11414. {
  11415. isSuccess = ConfigurationStatus_Rejected;
  11416. }
  11417. }
  11418. if(strcmp(key, "HeartbeatInterval") == 0)
  11419. {
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11421. {
  11422. check_ascii = value[0];
  11423. if( (check_ascii < 48) || (check_ascii > 57) )
  11424. {
  11425. isSuccess = ConfigurationStatus_Rejected;
  11426. }
  11427. else
  11428. {
  11429. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11431. HeartBeatWaitTime = atoi(value);
  11432. isSuccess = ConfigurationStatus_Accepted;
  11433. }
  11434. }
  11435. else
  11436. {
  11437. isSuccess = ConfigurationStatus_Rejected;
  11438. }
  11439. }
  11440. if(strcmp(key, "LightIntensity") == 0)
  11441. {
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11443. {
  11444. check_ascii = value[0];
  11445. if( (check_ascii < 48) || (check_ascii > 57) )
  11446. {
  11447. isSuccess = ConfigurationStatus_Rejected;
  11448. }
  11449. else
  11450. {
  11451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11452. isSuccess = ConfigurationStatus_Accepted;
  11453. }
  11454. }
  11455. else
  11456. {
  11457. isSuccess = ConfigurationStatus_Rejected;
  11458. }
  11459. }
  11460. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11461. {
  11462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11463. {
  11464. strcpy(str, (const char*)value);
  11465. for(int i = 0; str[i]; i++)
  11466. {
  11467. str[i] = tolower(str[i]);
  11468. }
  11469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11470. isSuccess = ConfigurationStatus_Accepted;
  11471. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11472. }
  11473. else
  11474. {
  11475. isSuccess = ConfigurationStatus_Rejected;
  11476. }
  11477. }
  11478. if(strcmp(key, "LocalPreAuthorize") == 0)
  11479. {
  11480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11481. {
  11482. strcpy(str, (const char*)value);
  11483. for(int i = 0; str[i]; i++)
  11484. {
  11485. str[i] = tolower(str[i]);
  11486. }
  11487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11488. isSuccess = ConfigurationStatus_Accepted;
  11489. }
  11490. else
  11491. {
  11492. isSuccess = ConfigurationStatus_Rejected;
  11493. }
  11494. }
  11495. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11496. {
  11497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11498. {
  11499. check_ascii = value[0];
  11500. if( (check_ascii < 48) || (check_ascii > 57) )
  11501. {
  11502. isSuccess = ConfigurationStatus_Rejected;
  11503. }
  11504. else
  11505. {
  11506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11507. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11508. isSuccess = ConfigurationStatus_Accepted;
  11509. }
  11510. }
  11511. else
  11512. {
  11513. isSuccess = ConfigurationStatus_Rejected;
  11514. }
  11515. }
  11516. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11517. {
  11518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11519. {
  11520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11521. isSuccess = ConfigurationStatus_Accepted;
  11522. }
  11523. else
  11524. {
  11525. isSuccess = ConfigurationStatus_Rejected;
  11526. }
  11527. }
  11528. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11529. {
  11530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11531. {
  11532. check_ascii = value[0];
  11533. if( (check_ascii < 48) || (check_ascii > 57) )
  11534. {
  11535. isSuccess = ConfigurationStatus_Rejected;
  11536. }
  11537. else
  11538. {
  11539. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11541. isSuccess = ConfigurationStatus_Accepted;
  11542. }
  11543. }
  11544. else
  11545. {
  11546. isSuccess = ConfigurationStatus_Rejected;
  11547. }
  11548. }
  11549. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11550. {
  11551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11552. {
  11553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11554. isSuccess = ConfigurationStatus_Accepted;
  11555. }
  11556. else
  11557. {
  11558. isSuccess = ConfigurationStatus_Rejected;
  11559. }
  11560. }
  11561. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11562. {
  11563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11564. {
  11565. check_ascii = value[0];
  11566. if( (check_ascii < 48) || (check_ascii > 57) )
  11567. {
  11568. isSuccess = ConfigurationStatus_Rejected;
  11569. }
  11570. else
  11571. {
  11572. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11574. isSuccess = ConfigurationStatus_Accepted;
  11575. }
  11576. }
  11577. else
  11578. {
  11579. isSuccess = ConfigurationStatus_Rejected;
  11580. }
  11581. }
  11582. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11583. {
  11584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11585. {
  11586. check_ascii = value[0];
  11587. if( (check_ascii < 48) || (check_ascii > 57) )
  11588. {
  11589. isSuccess = ConfigurationStatus_Rejected;
  11590. }
  11591. else
  11592. {
  11593. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11595. isSuccess = ConfigurationStatus_Accepted;
  11596. }
  11597. }
  11598. else
  11599. {
  11600. isSuccess = ConfigurationStatus_Rejected;
  11601. }
  11602. }
  11603. if(strcmp(key, "MinimumStatusDuration") == 0)
  11604. {
  11605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11606. {
  11607. check_ascii = value[0];
  11608. if( (check_ascii < 48) || (check_ascii > 57) )
  11609. {
  11610. isSuccess = ConfigurationStatus_Rejected;
  11611. }
  11612. else
  11613. {
  11614. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11615. {
  11616. isSuccess = ConfigurationStatus_Rejected;
  11617. }
  11618. else
  11619. {
  11620. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11622. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11623. isSuccess = ConfigurationStatus_Accepted;
  11624. }
  11625. }
  11626. }
  11627. else
  11628. {
  11629. isSuccess = ConfigurationStatus_Rejected;
  11630. }
  11631. }
  11632. if(strcmp(key, "NumberOfConnectors") == 0)
  11633. {
  11634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11635. {
  11636. check_ascii = value[0];
  11637. if( (check_ascii < 48) || (check_ascii > 57) )
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. else
  11642. {
  11643. //Charger.ResetRetries = Integer.parseInt(value);
  11644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11645. isSuccess = ConfigurationStatus_Accepted;
  11646. }
  11647. }
  11648. else
  11649. {
  11650. isSuccess = ConfigurationStatus_Rejected;
  11651. }
  11652. }
  11653. if(strcmp(key, "ResetRetries") == 0)
  11654. {
  11655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11656. {
  11657. check_ascii = value[0];
  11658. if( (check_ascii < 48) || (check_ascii > 57) )
  11659. {
  11660. isSuccess = ConfigurationStatus_Rejected;
  11661. }
  11662. else
  11663. {
  11664. //Charger.ResetRetries = Integer.parseInt(value);
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11666. isSuccess = ConfigurationStatus_Accepted;
  11667. }
  11668. }
  11669. else
  11670. {
  11671. isSuccess = ConfigurationStatus_Rejected;
  11672. }
  11673. }
  11674. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11675. {
  11676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11677. {
  11678. strcpy(str, (const char*)value);
  11679. for(int i = 0; str[i]; i++)
  11680. {
  11681. str[i] = tolower(str[i]);
  11682. }
  11683. if(strcmp(str, "notapplicable")== 0)
  11684. {
  11685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11686. isSuccess = ConfigurationStatus_Accepted;
  11687. }
  11688. else if(strcmp(str, "unknown")== 0)
  11689. {
  11690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11691. isSuccess = ConfigurationStatus_Accepted;
  11692. }
  11693. else if(strcmp(str, "rst")== 0)
  11694. {
  11695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11696. isSuccess = ConfigurationStatus_Accepted;
  11697. }
  11698. else if(strcmp(str, "rts")== 0)
  11699. {
  11700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11701. isSuccess = ConfigurationStatus_Accepted;
  11702. }
  11703. else if(strcmp(str, "srt")== 0)
  11704. {
  11705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11706. isSuccess = ConfigurationStatus_Accepted;
  11707. }
  11708. else if(strcmp(str, "str")== 0)
  11709. {
  11710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11711. isSuccess = ConfigurationStatus_Accepted;
  11712. }
  11713. else if(strcmp(str, "trs")== 0)
  11714. {
  11715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11716. isSuccess = ConfigurationStatus_Accepted;
  11717. }
  11718. else if(strcmp(str, "tsr")== 0)
  11719. {
  11720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11721. isSuccess = ConfigurationStatus_Accepted;
  11722. }
  11723. else
  11724. {
  11725. isSuccess = ConfigurationStatus_Rejected;
  11726. }
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11736. {
  11737. check_ascii = value[0];
  11738. if( (check_ascii < 48) || (check_ascii > 57) )
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. else
  11743. {
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11745. isSuccess = ConfigurationStatus_Accepted;
  11746. }
  11747. }
  11748. else
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. }
  11753. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11754. {
  11755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11756. {
  11757. strcpy(str, (const char*)value);
  11758. for(int i = 0; str[i]; i++)
  11759. {
  11760. str[i] = tolower(str[i]);
  11761. }
  11762. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11764. isSuccess = ConfigurationStatus_Accepted;
  11765. }
  11766. else
  11767. {
  11768. isSuccess = ConfigurationStatus_Rejected;
  11769. }
  11770. }
  11771. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11772. {
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11774. {
  11775. strcpy(str, (const char*)value);
  11776. for(int i = 0; str[i]; i++)
  11777. {
  11778. str[i] = tolower(str[i]);
  11779. }
  11780. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11782. isSuccess = ConfigurationStatus_Accepted;
  11783. }
  11784. else
  11785. {
  11786. isSuccess = ConfigurationStatus_Rejected;
  11787. }
  11788. }
  11789. if(strcmp(key, "StopTxnAlignedData") == 0)
  11790. {
  11791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11792. {
  11793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11794. isSuccess = ConfigurationStatus_Accepted;
  11795. }
  11796. else
  11797. {
  11798. isSuccess = ConfigurationStatus_Rejected;
  11799. }
  11800. }
  11801. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11802. {
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11804. {
  11805. check_ascii = value[0];
  11806. if( (check_ascii < 48) || (check_ascii > 57) )
  11807. {
  11808. isSuccess = ConfigurationStatus_Rejected;
  11809. }
  11810. else
  11811. {
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11813. isSuccess = ConfigurationStatus_Accepted;
  11814. }
  11815. }
  11816. else
  11817. {
  11818. isSuccess = ConfigurationStatus_Rejected;
  11819. }
  11820. }
  11821. if(strcmp(key, "StopTxnSampledData") == 0)
  11822. {
  11823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11824. {
  11825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11826. isSuccess = ConfigurationStatus_Accepted;
  11827. }
  11828. else
  11829. {
  11830. isSuccess = ConfigurationStatus_Rejected;
  11831. }
  11832. }
  11833. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11834. {
  11835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11836. {
  11837. check_ascii = value[0];
  11838. if( (check_ascii < 48) || (check_ascii > 57) )
  11839. {
  11840. isSuccess = ConfigurationStatus_Rejected;
  11841. }
  11842. else
  11843. {
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11845. isSuccess = ConfigurationStatus_Accepted;
  11846. }
  11847. }
  11848. else
  11849. {
  11850. isSuccess = ConfigurationStatus_Rejected;
  11851. }
  11852. }
  11853. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11854. {
  11855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11856. {
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11858. isSuccess = ConfigurationStatus_Accepted;
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11866. {
  11867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11868. {
  11869. check_ascii = value[0];
  11870. if( (check_ascii < 48) || (check_ascii > 57) )
  11871. {
  11872. isSuccess = ConfigurationStatus_Rejected;
  11873. }
  11874. else
  11875. {
  11876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11877. isSuccess = ConfigurationStatus_Accepted;
  11878. }
  11879. }
  11880. else
  11881. {
  11882. isSuccess = ConfigurationStatus_Rejected;
  11883. }
  11884. }
  11885. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11886. {
  11887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11888. {
  11889. check_ascii = value[0];
  11890. if( (check_ascii < 48) || (check_ascii > 57) )
  11891. {
  11892. isSuccess = ConfigurationStatus_Rejected;
  11893. }
  11894. else
  11895. {
  11896. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11898. TransactionMessageAttemptsValue = atoi(value);
  11899. isSuccess = ConfigurationStatus_Accepted;
  11900. }
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11910. {
  11911. check_ascii = value[0];
  11912. if( (check_ascii < 48) || (check_ascii > 57) )
  11913. {
  11914. isSuccess = ConfigurationStatus_Rejected;
  11915. }
  11916. else
  11917. {
  11918. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11920. TransactionMessageRetryIntervalValue = atoi(value);
  11921. isSuccess = ConfigurationStatus_Accepted;
  11922. }
  11923. }
  11924. else
  11925. {
  11926. isSuccess = ConfigurationStatus_Rejected;
  11927. }
  11928. }
  11929. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11930. {
  11931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11932. {
  11933. strcpy(str, (const char*)value);
  11934. for(int i = 0; str[i]; i++)
  11935. {
  11936. str[i] = tolower(str[i]);
  11937. }
  11938. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11940. isSuccess = ConfigurationStatus_Accepted;
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. if(strcmp(key, "WebSocketPingInterval") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11950. {
  11951. check_ascii = value[0];
  11952. if( (check_ascii < 48) || (check_ascii > 57) )
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. else
  11957. {
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11959. isSuccess = ConfigurationStatus_Accepted;
  11960. }
  11961. }
  11962. else
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. }
  11967. #if 0
  11968. //For OCPP Test Case
  11969. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11970. {
  11971. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11972. {
  11973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11974. isSuccess = ConfigurationStatus_Accepted;
  11975. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11976. }
  11977. else
  11978. {
  11979. isSuccess = ConfigurationStatus_Rejected;
  11980. }
  11981. }
  11982. #endif
  11983. #if 1
  11984. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11985. {
  11986. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11987. {
  11988. strcpy(str, (const char*)value);
  11989. for(int i = 0; str[i]; i++)
  11990. {
  11991. str[i] = tolower(str[i]);
  11992. }
  11993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11994. isSuccess = ConfigurationStatus_Accepted;
  11995. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11996. }
  11997. else
  11998. {
  11999. isSuccess = ConfigurationStatus_Rejected;
  12000. }
  12001. }
  12002. #endif
  12003. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12004. {
  12005. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12006. {
  12007. check_ascii = value[0];
  12008. if( (check_ascii < 48) || (check_ascii > 57) )
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. else
  12013. {
  12014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12015. isSuccess = ConfigurationStatus_Accepted;
  12016. }
  12017. }
  12018. else
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. }
  12023. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12024. {
  12025. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12026. {
  12027. check_ascii = value[0];
  12028. if( (check_ascii < 48) || (check_ascii > 57) )
  12029. {
  12030. isSuccess = ConfigurationStatus_Rejected;
  12031. }
  12032. else
  12033. {
  12034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12035. isSuccess = ConfigurationStatus_Accepted;
  12036. }
  12037. }
  12038. else
  12039. {
  12040. isSuccess = ConfigurationStatus_Rejected;
  12041. }
  12042. }
  12043. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12044. {
  12045. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12046. {
  12047. strcpy(str, (const char*)value);
  12048. for(int i = 0; str[i]; i++)
  12049. {
  12050. str[i] = tolower(str[i]);
  12051. }
  12052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12053. isSuccess = ConfigurationStatus_Accepted;
  12054. }
  12055. else
  12056. {
  12057. isSuccess = ConfigurationStatus_Rejected;
  12058. }
  12059. }
  12060. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12061. {
  12062. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12063. {
  12064. check_ascii = value[0];
  12065. if( (check_ascii < 48) || (check_ascii > 57) )
  12066. {
  12067. isSuccess = ConfigurationStatus_Rejected;
  12068. }
  12069. else
  12070. {
  12071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12072. isSuccess = ConfigurationStatus_Accepted;
  12073. }
  12074. }
  12075. else
  12076. {
  12077. isSuccess = ConfigurationStatus_Rejected;
  12078. }
  12079. }
  12080. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12081. {
  12082. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12083. {
  12084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12085. isSuccess = ConfigurationStatus_Accepted;
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12095. {
  12096. check_ascii = value[0];
  12097. if( (check_ascii < 48) || (check_ascii > 57) )
  12098. {
  12099. isSuccess = ConfigurationStatus_Rejected;
  12100. }
  12101. else
  12102. {
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. }
  12107. else
  12108. {
  12109. isSuccess = ConfigurationStatus_Rejected;
  12110. }
  12111. }
  12112. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12113. {
  12114. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12115. {
  12116. strcpy(str, (const char*)value);
  12117. for(int i = 0; str[i]; i++)
  12118. {
  12119. str[i] = tolower(str[i]);
  12120. }
  12121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12122. isSuccess = ConfigurationStatus_Accepted;
  12123. }
  12124. else
  12125. {
  12126. isSuccess = ConfigurationStatus_Rejected;
  12127. }
  12128. }
  12129. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12130. {
  12131. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12132. {
  12133. check_ascii = value[0];
  12134. if( (check_ascii < 48) || (check_ascii > 57) )
  12135. {
  12136. isSuccess = ConfigurationStatus_Rejected;
  12137. }
  12138. else
  12139. {
  12140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12141. isSuccess = ConfigurationStatus_Accepted;
  12142. }
  12143. }
  12144. else
  12145. {
  12146. isSuccess = ConfigurationStatus_Rejected;
  12147. }
  12148. }
  12149. return isSuccess;
  12150. }
  12151. int updateSetting(char *key, char *value)
  12152. {
  12153. mtrace();
  12154. int isSuccess = FALSE;
  12155. char string[1000]={0}, buffer[1000]={0};
  12156. char strtemp[50]={0};
  12157. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12158. int pos, c = 0;
  12159. char *loc;
  12160. int pos1=0;
  12161. FILE *f = fopen("/var/www/settings1", "r");
  12162. if(f == NULL)
  12163. {
  12164. #ifdef Debug
  12165. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12166. #endif
  12167. return isSuccess;
  12168. }
  12169. fseek(f, 0, SEEK_END);
  12170. long fsize = ftell(f);
  12171. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12172. fread(string, 1, fsize, f);
  12173. fclose(f);
  12174. string[fsize] = 0;
  12175. loc = strstr(string, key);
  12176. if(loc != NULL)
  12177. {
  12178. DEBUG_INFO("key exist!\n");
  12179. pos = loc - string-1;
  12180. f = fopen("/var/www/settings1", "w");
  12181. strncpy(buffer, string, pos);
  12182. fprintf(f, "%s", buffer);
  12183. memset(sstr ,0, sizeof(sstr) );
  12184. c = 0;
  12185. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12186. {
  12187. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12188. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12189. c++;
  12190. }
  12191. sstr[c] = '\0';
  12192. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12193. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12194. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12195. memset(buffer ,0, sizeof(buffer) );
  12196. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12197. //printf("buffer=%s",buffer);
  12198. fprintf(f, "%s", buffer);
  12199. fclose(f);
  12200. }
  12201. else
  12202. {
  12203. printf("key not exist!\n");
  12204. f = fopen("/var/www/settings1", "w+");
  12205. fputs(string, f);
  12206. fseek(f, -1, SEEK_CUR);
  12207. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12208. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12209. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12210. fclose(f);
  12211. }
  12212. isSuccess = TRUE;
  12213. return isSuccess;
  12214. }
  12215. int TransactionMessageAttemptsGet(void)
  12216. {
  12217. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12218. }
  12219. int FirstHeartBeatResponse(void)
  12220. {
  12221. return FirstHeartBeat;
  12222. }
  12223. int TransactionMessageRetryIntervalGet(void)
  12224. {
  12225. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12226. }
  12227. #define SA struct sockaddr
  12228. #define MAXBUF 1024
  12229. //static int m_socket_data;
  12230. //static int sockfd;
  12231. int ReadHttpStatus(int sock){
  12232. //char c;
  12233. char buff[1024]="",*ptr=buff+1;
  12234. int bytes_received, status;
  12235. DEBUG_INFO("Begin Response ..\n");
  12236. while((bytes_received = recv(sock, ptr, 1, 0))){
  12237. if(bytes_received==-1){
  12238. perror("ReadHttpStatus");
  12239. exit(1);
  12240. }
  12241. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12242. ptr++;
  12243. }
  12244. *ptr=0;
  12245. ptr=buff+1;
  12246. sscanf(ptr,"%*s %d ", &status);
  12247. DEBUG_INFO("%s\n",ptr);
  12248. DEBUG_INFO("status=%d\n",status);
  12249. DEBUG_INFO("End Response ..\n");
  12250. return (bytes_received>0)?status:0;
  12251. }
  12252. //the only filed that it parsed is 'Content-Length'
  12253. int ParseHeader(int sock){
  12254. //char c;
  12255. char buff[1024]="",*ptr=buff+4;
  12256. int bytes_received;
  12257. DEBUG_INFO("Begin HEADER ..\n");
  12258. while((bytes_received = recv(sock, ptr, 1, 0))){
  12259. if(bytes_received==-1){
  12260. perror("Parse Header");
  12261. exit(1);
  12262. }
  12263. if(
  12264. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12265. (ptr[-1]=='\r') && (*ptr=='\n' )
  12266. ) break;
  12267. ptr++;
  12268. }
  12269. *ptr=0;
  12270. ptr=buff+4;
  12271. //printf("%s",ptr);
  12272. if(bytes_received){
  12273. ptr=strstr(ptr,"Content-Length:");
  12274. if(ptr){
  12275. sscanf(ptr,"%*s %d",&bytes_received);
  12276. }else
  12277. bytes_received=-1; //unknown size
  12278. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12279. }
  12280. DEBUG_INFO("End HEADER ..\n");
  12281. return bytes_received ;
  12282. }
  12283. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12284. {
  12285. char rmFileCmd[100]={0};
  12286. char FilePath[100]={0};
  12287. char ftpbuf[200];
  12288. int systemresult;
  12289. //DEBUG_INFO("filename=%s\n",filename);
  12290. //DEBUG_INFO("url=%s\n",url);
  12291. sprintf(FilePath,"/mnt/%s",filename);
  12292. if((access(FilePath,F_OK))!=-1)
  12293. {
  12294. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12295. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12296. system(rmFileCmd);
  12297. }
  12298. memset(ftpbuf, 0, sizeof(ftpbuf));
  12299. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12300. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12301. systemresult = system(ftpbuf);
  12302. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12303. if(systemresult != 0)
  12304. {
  12305. DEBUG_INFO("http DownLoad error!\n");
  12306. return FALSE;
  12307. }
  12308. return TRUE;
  12309. }
  12310. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12311. {
  12312. char rmFileCmd[100]={0};
  12313. char FilePath[100]={0};
  12314. char ftpbuf[200];
  12315. int systemresult;
  12316. //char temp[100];
  12317. #if 0
  12318. struct hostent* server;
  12319. char *IPbuffer;
  12320. server = gethostbyname(location);
  12321. // To convert an Internet network
  12322. // address into ASCII string
  12323. IPbuffer = inet_ntoa(*((struct in_addr*)
  12324. server->h_addr_list[0]));
  12325. #endif
  12326. sprintf(FilePath,"/mnt/%s",filename);
  12327. if((access(FilePath,F_OK))!=-1)
  12328. {
  12329. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12330. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12331. system(rmFileCmd);
  12332. }
  12333. memset(ftpbuf, 0, sizeof(ftpbuf));
  12334. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12335. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12336. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12337. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12338. systemresult = system(ftpbuf);
  12339. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12340. if(systemresult != 0)
  12341. {
  12342. printf("wget error!\n");
  12343. return FALSE;
  12344. }
  12345. return TRUE;
  12346. }
  12347. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12348. {
  12349. char rmFileCmd[100]={0};
  12350. char FilePath[100]={0};
  12351. char ftpbuf[200];
  12352. char filenametemp[60]={0};
  12353. int systemresult;
  12354. //DEBUG_INFO("filename=%s\n",filename);
  12355. //DEBUG_INFO("url=%s\n",url);
  12356. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12357. if((access(FilePath,F_OK))!=-1)
  12358. {
  12359. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12360. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12361. system(rmFileCmd);
  12362. }
  12363. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12364. if(fp == NULL)
  12365. {
  12366. DEBUG_INFO("log is NULL\n");
  12367. return FALSE;
  12368. }
  12369. else
  12370. {
  12371. fprintf(fp, "%s\n", url);
  12372. sscanf(filename, "%*2[.]%s", filenametemp);
  12373. fprintf(fp, "%s\n", filenametemp);
  12374. fclose(fp);
  12375. }
  12376. memset(ftpbuf, 0, sizeof(ftpbuf));
  12377. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12378. systemresult = system(ftpbuf);
  12379. DEBUG_INFO("systemresult=%d\n",systemresult);
  12380. if(systemresult != 0)
  12381. {
  12382. DEBUG_INFO("http upload error!\n");
  12383. return FALSE;
  12384. }
  12385. return TRUE;
  12386. }
  12387. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12388. {
  12389. struct hostent* server;
  12390. char *IPbuffer;
  12391. char ftpbuf[200];
  12392. int systemresult;
  12393. // To retrieve host information
  12394. server = gethostbyname(location);
  12395. // To convert an Internet network
  12396. // address into ASCII string
  12397. IPbuffer = inet_ntoa(*((struct in_addr*)
  12398. server->h_addr_list[0]));
  12399. memset(ftpbuf, 0, sizeof(ftpbuf));
  12400. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12401. /* format : ftpput -u username -p passwd IP target source*/
  12402. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12403. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12404. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12405. systemresult = system(ftpbuf);
  12406. DEBUG_INFO("systemresult=%d\n",systemresult);
  12407. if(systemresult != 0)
  12408. {
  12409. DEBUG_INFO("ftpput error!\n");
  12410. return FALSE;
  12411. }
  12412. return TRUE;
  12413. }
  12414. int SettingChargingRecord(int target, int transactionId)
  12415. {
  12416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12417. {
  12418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12419. {
  12420. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12421. {
  12422. addBuff(target, transactionId, 0);
  12423. return TRUE;
  12424. }
  12425. }
  12426. for (int index = 0; index < CCS_QUANTITY; index++)
  12427. {
  12428. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12429. {
  12430. addBuff(target, transactionId, 0);
  12431. return TRUE;
  12432. }
  12433. }
  12434. for (int index = 0; index < GB_QUANTITY; index++)
  12435. {
  12436. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12437. {
  12438. addBuff(target, transactionId, 0);
  12439. return TRUE;
  12440. }
  12441. }
  12442. }
  12443. else
  12444. {
  12445. for (int index = 0; index < AC_QUANTITY; index++)
  12446. {
  12447. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12448. {
  12449. addBuff(target, transactionId, 0);
  12450. return TRUE;
  12451. }
  12452. }
  12453. }
  12454. return FALSE;
  12455. }
  12456. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12457. {
  12458. int isSuccess = FALSE;
  12459. //char *query = NULL;
  12460. sqlite3_stmt *stmt;
  12461. int rc; // return code
  12462. char str[20];
  12463. sprintf(str,"%d",user_id);
  12464. 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 */
  12465. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12466. rc = sqlite3_step(stmt); /* 3 */
  12467. if (rc != SQLITE_DONE) {
  12468. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12469. goto out;
  12470. }
  12471. sqlite3_finalize(stmt);
  12472. // free(query);
  12473. out:
  12474. //----------------------
  12475. // close SQLite database
  12476. //----------------------
  12477. sqlite3_close(db);
  12478. printf("database closed.\n");
  12479. return isSuccess;
  12480. }
  12481. /**
  12482. * Place the contents of the specified file into a memory buffer
  12483. *
  12484. * @param[in] filename The path and name of the file to read
  12485. * @param[out] filebuffer A pointer to the contents in memory
  12486. * @return status 0 success, 1 on failure
  12487. */
  12488. int get_file_contents(const char* filename, char** outbuffer) {
  12489. FILE* file = NULL;
  12490. long filesize;
  12491. const int blocksize = 1;
  12492. size_t readsize;
  12493. char* filebuffer;
  12494. // Open the file
  12495. file = fopen(filename, "r");
  12496. if (NULL == file)
  12497. {
  12498. printf("'%s' not opened\n", filename);
  12499. exit(EXIT_FAILURE);
  12500. }
  12501. // Determine the file size
  12502. fseek(file, 0, SEEK_END);
  12503. filesize = ftell(file);
  12504. rewind (file);
  12505. // Allocate memory for the file contents
  12506. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12507. *outbuffer = filebuffer;
  12508. if (filebuffer == NULL)
  12509. {
  12510. fputs ("malloc out-of-memory", stderr);
  12511. exit(EXIT_FAILURE);
  12512. }
  12513. // Read in the file
  12514. readsize = fread(filebuffer, blocksize, filesize, file);
  12515. if (readsize != filesize)
  12516. {
  12517. fputs ("didn't read file completely",stderr);
  12518. exit(EXIT_FAILURE);
  12519. }
  12520. // Clean exit
  12521. fclose(file);
  12522. return EXIT_SUCCESS;
  12523. }
  12524. static int selectSqlCount = 0;
  12525. static int callback(void *data, int argc, char **argv, char **azColName){
  12526. int i;
  12527. //printf("%s: ", (const char*)data);
  12528. selectSqlCount = argc;
  12529. for(i = 0; i<argc; i++){
  12530. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12531. }
  12532. //printf("\n");
  12533. return 0;
  12534. }
  12535. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12536. //int i;
  12537. //printf("%s:\n", (const char*)data);
  12538. localversion = argv[5] ? atoi(argv[5]) : 0;
  12539. //printf("localversion=%d\n", localversion);
  12540. return 0;
  12541. }
  12542. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12543. //int i;
  12544. //printf("%s:\n", (const char*)data);
  12545. //idTag
  12546. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12547. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12548. //parentIdTag
  12549. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12550. //expir_date
  12551. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12552. //status
  12553. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12554. //version
  12555. idTagQuery.listVersionInt = atoi(argv[5]);
  12556. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12557. return 0;
  12558. }
  12559. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12560. #if 0
  12561. int i;
  12562. //printf("%s:\n", (const char*)data);
  12563. for(i=0; i<argc; i++){
  12564. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12565. }
  12566. //printf("");
  12567. #endif
  12568. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12569. // printf("localversion=%d\n", localversion);
  12570. return 0;
  12571. }
  12572. /** sqlite3_exec的回调。
  12573. *
  12574. * 向控制台打印查询的结果。
  12575. *
  12576. * @param in data 传递给回调函数的数据。
  12577. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12578. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12579. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12580. * @return 状态码。
  12581. */
  12582. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12583. {
  12584. for (int i = 0; i < n_columns; i++)
  12585. {
  12586. DEBUG_INFO("%s/t", col_values[i]);
  12587. }
  12588. DEBUG_INFO("/n");
  12589. return 0;
  12590. }
  12591. void OCPP_getListVerion()
  12592. {
  12593. int rc = 0;
  12594. // const char* data = "Callback function called";
  12595. char sql[100];
  12596. char zErrMsg[100];
  12597. memset(sql, 0, 100);
  12598. memset(zErrMsg, 0, 100);
  12599. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12600. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12601. /* Execute SQL statement */
  12602. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12603. DEBUG_INFO("rc=%d\n",rc);
  12604. if( rc != SQLITE_OK ){
  12605. DEBUG_INFO("SQL error: %s", zErrMsg);
  12606. //sqlite3_free(zErrMsg);
  12607. }
  12608. }
  12609. void OCPP_getIdTag(char idTag[])
  12610. {
  12611. int rc = 0;
  12612. // const char* data = "Callback function called";
  12613. char sql[100];
  12614. char zErrMsg[100];
  12615. memset(sql, 0, 100);
  12616. memset(zErrMsg, 0, 100);
  12617. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12618. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12619. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12620. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12621. /* Execute SQL statement */
  12622. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12623. if( rc != SQLITE_OK ){
  12624. DEBUG_INFO("SQL error: %s", zErrMsg);
  12625. //sqlite3_free(zErrMsg);
  12626. }
  12627. //return ver;
  12628. }
  12629. void OCPP_get_TableAuthlocalAllData(void)
  12630. {
  12631. int rc = 0;
  12632. // const char* data = "Callback function called";
  12633. char sql[100];
  12634. char zErrMsg[100];
  12635. memset(sql, 0, 100);
  12636. memset(zErrMsg, 0, 100);
  12637. sprintf(sql,"select * from ocpp_auth_local ");
  12638. /* Execute SQL statement */
  12639. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12640. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12641. if( rc != SQLITE_OK ){
  12642. DEBUG_INFO("SQL error: %s", zErrMsg);
  12643. //sqlite3_free(zErrMsg);
  12644. }
  12645. //return ver;
  12646. }
  12647. int OCPP_cleanLocalList()
  12648. {
  12649. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12650. char *errMsg = 0;
  12651. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12652. if (SQLITE_OK != rc)
  12653. {
  12654. DEBUG_INFO("%s\n",errMsg);
  12655. return FALSE;
  12656. }
  12657. else
  12658. {
  12659. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12660. }
  12661. return TRUE;
  12662. }
  12663. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12664. {
  12665. int isSuccess = FALSE;
  12666. int ret = 0;
  12667. //const char* data = "Callback function called";
  12668. char sql[300];
  12669. char zErrMsg[200];
  12670. memset(sql, 0, 300);
  12671. memset(zErrMsg, 0, 200);
  12672. 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);
  12673. //* Execute SQL statement */
  12674. //zErrMsg = 0;
  12675. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12676. if( ret != SQLITE_OK ){
  12677. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12678. // free(zErrMsg);
  12679. // free(sql);
  12680. return isSuccess;
  12681. }
  12682. memset(sql, 0, 300);
  12683. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12684. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12685. if( ret != SQLITE_OK ){
  12686. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12687. // free(zErrMsg);
  12688. // free(sql);
  12689. return isSuccess;
  12690. }
  12691. // DEBUG_INFO("successfully Insert records created\n");
  12692. isSuccess = TRUE;
  12693. return isSuccess;
  12694. }
  12695. void OCPP_deleteIdTag(char idTag[])
  12696. {
  12697. //int ver = 0;
  12698. //int isSuccess = FALSE;
  12699. int rc = 0;
  12700. char sql[100];
  12701. char zErrMsg[100];
  12702. memset(sql, 0, 100);
  12703. memset(zErrMsg, 0, 100);
  12704. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12705. //* Execute SQL statement */
  12706. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12707. if( rc != SQLITE_OK ){
  12708. DEBUG_INFO("SQL error: %s", zErrMsg);
  12709. //sqlite3_free(zErrMsg);
  12710. }
  12711. }
  12712. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12713. {
  12714. int isSuccess = FALSE;
  12715. int ret = 0;
  12716. const char* data = "Callback function called";
  12717. char sql[200];
  12718. char zErrMsg[100];
  12719. memset(sql, 0, 200);
  12720. memset(zErrMsg, 0, 100);
  12721. //* selectFromTable */
  12722. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12723. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12724. //* Execute SQL statement */
  12725. selectSqlCount = 0;
  12726. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12727. if( ret != SQLITE_OK ){
  12728. printf("Error SQL: %s\n", zErrMsg);
  12729. }
  12730. printf("successfully select operation done\n");
  12731. memset(sql, 0, 200);
  12732. memset(zErrMsg, 0, 100);
  12733. if(selectSqlCount == 0)
  12734. {
  12735. //Insert
  12736. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12737. 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);
  12738. DEBUG_INFO("sql:%s\n", sql);
  12739. //* Execute SQL statement */
  12740. //zErrMsg = 0;
  12741. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12742. if( ret != SQLITE_OK ){
  12743. printf("SQL error: %s\n", zErrMsg);
  12744. return isSuccess;
  12745. }
  12746. DEBUG_INFO("successfully Insert records created\n");
  12747. isSuccess = TRUE;
  12748. }
  12749. else
  12750. {
  12751. //Update
  12752. //* Create merged SQL statement */
  12753. 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);
  12754. /* Execute SQL statement */
  12755. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12756. if( ret != SQLITE_OK ){
  12757. printf("SQL error: %s\n", zErrMsg);
  12758. //sqlite3_free(zErrMsg);
  12759. //sqlite3_free(sql);
  12760. return isSuccess;
  12761. }
  12762. DEBUG_INFO("Successfully operation done \n");
  12763. isSuccess = TRUE;
  12764. }
  12765. return isSuccess;
  12766. }
  12767. int GetOcppServerURL()
  12768. {
  12769. int result = FALSE;
  12770. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12771. memset(OcppHost, 0, sizeof(OcppHost));
  12772. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12773. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12774. {
  12775. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12776. #if 1
  12777. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12778. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12779. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12780. #endif
  12781. #if 0
  12782. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12783. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  12784. OcppProtocol, OcppHost, OcppTempPath);
  12785. OcppPort = 443;
  12786. #endif
  12787. result = TRUE;
  12788. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12789. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12790. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12791. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12792. goto End;
  12793. }
  12794. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12795. {
  12796. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12797. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12798. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12799. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12800. result = TRUE;
  12801. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12802. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12803. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12804. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12805. goto End;
  12806. }
  12807. else
  12808. {
  12809. strcpy(OcppHost,"");
  12810. }
  12811. End:
  12812. return result;
  12813. }
  12814. int GetOcppPath()
  12815. {
  12816. int result = FALSE;
  12817. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12818. {
  12819. if(OcppTempPath == NULL)
  12820. {
  12821. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12822. }
  12823. else
  12824. {
  12825. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12826. }
  12827. result = TRUE;
  12828. goto End;
  12829. }
  12830. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12831. {
  12832. if(OcppTempPath == NULL)
  12833. {
  12834. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12835. }
  12836. else
  12837. {
  12838. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12839. }
  12840. result = TRUE;
  12841. goto End;
  12842. }
  12843. else
  12844. {
  12845. strcpy(OcppPath,"");
  12846. }
  12847. End:
  12848. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12849. return result;
  12850. }
  12851. int GetOcppPort()
  12852. {
  12853. return OcppPort;
  12854. }
  12855. int GetOcppConnStatus(void)
  12856. {
  12857. return ShmOCPP16Data->OcppConnStatus;
  12858. }
  12859. void SetOcppConnStatus(uint8_t status)
  12860. {
  12861. ShmOCPP16Data->OcppConnStatus = status;
  12862. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12863. if(status == FALSE)
  12864. {
  12865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12866. {
  12867. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12868. }
  12869. else
  12870. {
  12871. SystemInitial = AC_QUANTITY;
  12872. }
  12873. }
  12874. }
  12875. int GetHeartBeatWithNOResponse(void)
  12876. {
  12877. return HeartBeatWithNOResponse;
  12878. }
  12879. void SetHeartBeatWithNOResponse(void)
  12880. {
  12881. HeartBeatWithNOResponse = 0;
  12882. }
  12883. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12884. /*
  12885. src 源字串的首地址(buf的地址)
  12886. separator 指定的分割字元
  12887. dest 接收子字串的陣列
  12888. num 分割後子字串的個數
  12889. */
  12890. char *pNext;
  12891. int count = 0;
  12892. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12893. return;
  12894. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12895. return;
  12896. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12897. while(pNext != NULL) {
  12898. *dest++ = pNext;
  12899. ++count;
  12900. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12901. }
  12902. *num = count;
  12903. }
  12904. int GetTransactionId(int gunindex, unsigned char idTag[])
  12905. {
  12906. char ch;
  12907. FILE *fptr1;
  12908. int temptransactionId;
  12909. char str[100]={0};
  12910. temptransactionId = 0;
  12911. /*------ Read the file ----------------*/
  12912. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12913. if (!fptr1)
  12914. {
  12915. printf(" File not found or unable to open the input file!!\n");
  12916. return temptransactionId;
  12917. }
  12918. ch=fgetc(fptr1);
  12919. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12920. rewind(fptr1);
  12921. if(ch!=EOF)
  12922. {
  12923. // printf("%c",ch);
  12924. while (fgets(str, 100, fptr1) != NULL)
  12925. {
  12926. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12927. if(str[0]=='\0')
  12928. {
  12929. break;
  12930. }
  12931. char *revbuf[8] = {0}; //存放分割後的子字串
  12932. int num = 0;//分割後子字串的個數
  12933. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12934. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12935. {
  12936. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12937. {
  12938. temptransactionId = atoi(revbuf[2]);
  12939. break;
  12940. }
  12941. }
  12942. }
  12943. }
  12944. fclose(fptr1);
  12945. /*------- End of reading ---------------*/
  12946. return temptransactionId;
  12947. }
  12948. void SetTransactionIdZero(int transactionId)
  12949. {
  12950. //TransactionId[gunindex] = 0;
  12951. char ch;
  12952. FILE *fptr1, *fptr2;
  12953. int temptransactionId = 0;
  12954. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12955. printf("\n\n Delete a specific line from a file :\n");
  12956. printf("-----------------------------------------\n");
  12957. //scanf("%s",fname);
  12958. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12959. if (!fptr1)
  12960. {
  12961. printf(" File not found or unable to open the input file!!\n");
  12962. return ;
  12963. }
  12964. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12965. if (!fptr2)
  12966. {
  12967. printf("Unable to open a temporary file to write!!\n");
  12968. fclose(fptr1);
  12969. return ;
  12970. }
  12971. ch=fgetc(fptr1);
  12972. //printf(" Now the content of the file %s is : \n",fname);
  12973. rewind(fptr1);
  12974. if(ch!=EOF)
  12975. {
  12976. // copy all contents to the temporary file except the specific line
  12977. while (fgets(str, 100, fptr1) != NULL)
  12978. {
  12979. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12980. if(str[0]=='\0')
  12981. {
  12982. break;
  12983. }
  12984. char *revbuf[8] = {0}; //存放分割後的子字串
  12985. int num = 0;//分割後子字串的個數
  12986. strcpy(strtemp, str);
  12987. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12988. if(revbuf[2][0] != '\0')
  12989. {
  12990. temptransactionId = atoi(revbuf[2]);
  12991. if(transactionId != temptransactionId)
  12992. {
  12993. fprintf(fptr2, "%s", strtemp);
  12994. }
  12995. }
  12996. }
  12997. }
  12998. fclose(fptr1);
  12999. fclose(fptr2);
  13000. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13001. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13002. /*------ Read the file ----------------*/
  13003. }
  13004. int InternetDisconnect(void)
  13005. {
  13006. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13007. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13008. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13009. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13010. }
  13011. void GetChargingProfileRequest(int gunindex)
  13012. {
  13013. mtrace();
  13014. //int connectorIdInt, durationInt;
  13015. //char chargingRateUnitStr[4]={0};
  13016. int tempdurationInt = 0;
  13017. int tempchargingProfileId = 0;
  13018. int tempstackLevel = 0;
  13019. int temptransactionId = 0;
  13020. float tempminChargingRateFloat = 0.0;
  13021. char tempchargingProfilePurposeStr[24]={0};
  13022. char tempchargingProfileKindStr[12]={0};
  13023. char temprecurrencyKindStr[8]={0};
  13024. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13025. char tempvalidToStr[28]={0};
  13026. int tempStartPeriodInt = 0;
  13027. float tempLimitInt = 0.0;//0.1;
  13028. int tempNumberPhasesInt=0;
  13029. char fname[200];
  13030. //char comfirmstr[20];
  13031. float MinChargingRate =0.0;
  13032. double diff_t;
  13033. struct tm tp;
  13034. FILE *fptr1;//, *fptr2;
  13035. int c = 0;
  13036. char * pch;
  13037. char *loc;
  13038. char sstr[200]={ 0 };
  13039. int n_chargingProfile = 0;
  13040. int n_SchedulePeriods = 0;
  13041. char SchedulePeriodList[10][200]={0};
  13042. char sLineWord[1600]={0};
  13043. char word[1000]={0};
  13044. int confirmPeriods = 0;
  13045. struct StructProfile ChargePointMaxProfile;
  13046. struct StructProfile TxDefaultProfile;
  13047. struct StructProfile TxProfile;
  13048. struct StructProfile TxDefaultProfiletemp[2]={0};
  13049. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13050. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13051. struct StructChargingProfile TxProfile_TEMP={0};
  13052. int TxDefaultProfileFileIsNull=FALSE;
  13053. int ChargePointMaxProfileIsNull=FALSE;
  13054. int TxProfileIsNull=FALSE;
  13055. // int CompositeSceduleIndex = 0;
  13056. char ChargePointMaxProfileScheduleStr[30]={0};
  13057. char TxDefaultProfileScheduleStr[30]={0};
  13058. char TxProfileScheduleStr[30]={0};
  13059. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13060. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13061. memset(&TxProfile,0,sizeof(struct StructProfile));
  13062. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13063. DEBUG_INFO("GetChargingProfileRequest\n");
  13064. //*****************************ChargePointMaxProfile******************************************/
  13065. strcpy(fname, ChargePointMaxProfile_JSON);
  13066. ChargePointMaxProfileIsNull=TRUE;
  13067. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13068. {
  13069. fptr1 = fopen(fname, "r");
  13070. int c;
  13071. c = fgetc(fptr1);
  13072. //DEBUG_INFO("c:%d\n",c);
  13073. rewind(fptr1);
  13074. if(c == EOF)
  13075. {
  13076. DEBUG_INFO("\n End of file reached.");
  13077. ChargePointMaxProfileIsNull=TRUE;
  13078. fclose(fptr1);
  13079. }
  13080. else
  13081. {
  13082. ChargePointMaxProfileIsNull=FALSE;
  13083. while(fscanf(fptr1, "%s", word) != EOF)
  13084. {
  13085. if(strcmp(word, "chargingProfileId") == 0)
  13086. {
  13087. n_chargingProfile = n_chargingProfile + 1;
  13088. }
  13089. }
  13090. rewind(fptr1);
  13091. //search Charging Profile Element
  13092. int i = 0;
  13093. int j = 0;
  13094. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13095. //***********chargingProfileId**************/
  13096. c = 0;
  13097. loc = strstr(sLineWord, "chargingProfileId");
  13098. //DEBUG_INFO("loc=%s\n",loc);
  13099. memset(sstr ,0, sizeof(sstr) );
  13100. if(loc != NULL)
  13101. {
  13102. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13103. {
  13104. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13105. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13106. c++;
  13107. }
  13108. sstr[c] = '\0';
  13109. tempchargingProfileId = atoi(sstr);
  13110. }
  13111. else
  13112. {
  13113. tempchargingProfileId = 0;
  13114. }
  13115. //***********stackLevel**************/
  13116. c = 0;
  13117. loc = strstr(sLineWord, "stackLevel");
  13118. //DEBUG_INFO("loc=%s\n",loc);
  13119. memset(sstr ,0, sizeof(sstr) );
  13120. if(loc != NULL)
  13121. {
  13122. while (loc[2+strlen("stackLevel")+c] != '\"')
  13123. {
  13124. sstr[c] = loc[2+strlen("stackLevel")+c];
  13125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13126. c++;
  13127. }
  13128. sstr[c] = '\0';
  13129. tempstackLevel = atoi(sstr);
  13130. }
  13131. else
  13132. {
  13133. tempstackLevel = 0;
  13134. }
  13135. //***********chargingProfilePurpose **************/
  13136. c = 0;
  13137. loc = strstr(sLineWord, "chargingProfilePurpose");
  13138. //DEBUG_INFO("loc=%s\n",loc);
  13139. memset(sstr ,0, sizeof(sstr) );
  13140. if(loc != NULL)
  13141. {
  13142. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13143. {
  13144. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13146. c++;
  13147. }
  13148. sstr[c] = '\0';
  13149. strcpy(tempchargingProfilePurposeStr,sstr);
  13150. }
  13151. else
  13152. {
  13153. strcpy(tempchargingProfilePurposeStr,"");
  13154. }
  13155. //***********chargingProfileKind **************/
  13156. c = 0;
  13157. loc = strstr(sLineWord, "chargingProfileKind");
  13158. //DEBUG_INFO("loc=%s\n",loc);
  13159. memset(sstr ,0, sizeof(sstr) );
  13160. if(loc != NULL)
  13161. {
  13162. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13163. {
  13164. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13165. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13166. c++;
  13167. }
  13168. sstr[c] = '\0';
  13169. strcpy(tempchargingProfileKindStr,sstr);
  13170. }
  13171. else
  13172. {
  13173. strcpy(tempchargingProfileKindStr,"");
  13174. }
  13175. //***********recurrencyKind **************/
  13176. c = 0;
  13177. loc = strstr(sLineWord, "recurrencyKind");
  13178. //DEBUG_INFO("loc=%s\n",loc);
  13179. memset(sstr ,0, sizeof(sstr) );
  13180. if(loc != NULL)
  13181. {
  13182. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13183. {
  13184. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13185. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13186. c++;
  13187. }
  13188. sstr[c] = '\0';
  13189. strcpy(temprecurrencyKindStr,sstr);
  13190. }
  13191. else
  13192. {
  13193. strcpy(temprecurrencyKindStr,"");
  13194. }
  13195. //***********validFrom**************/
  13196. c = 0;
  13197. loc = strstr(sLineWord, "validFrom");
  13198. //DEBUG_INFO("loc=%s\n",loc);
  13199. memset(sstr ,0, sizeof(sstr) );
  13200. if(loc != NULL)
  13201. {
  13202. while (loc[3+strlen("validFrom")+c] != '\"')
  13203. {
  13204. sstr[c] = loc[3+strlen("validFrom")+c];
  13205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13206. c++;
  13207. }
  13208. sstr[c] = '\0';
  13209. strcpy(tempvalidFromStr,sstr);
  13210. }
  13211. else
  13212. {
  13213. strcpy(tempvalidFromStr,"");
  13214. }
  13215. //***********validTo **************/
  13216. c = 0;
  13217. loc = strstr(sLineWord, "validTo");
  13218. //DEBUG_INFO("loc=%s\n",loc);
  13219. memset(sstr ,0, sizeof(sstr) );
  13220. if(loc != NULL)
  13221. {
  13222. while (loc[3+strlen("validTo")+c] != '\"')
  13223. {
  13224. sstr[c] = loc[3+strlen("validTo")+c];
  13225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13226. c++;
  13227. }
  13228. sstr[c] = '\0';
  13229. strcpy(tempvalidToStr,sstr);
  13230. }
  13231. else
  13232. {
  13233. strcpy(tempvalidToStr,"");
  13234. }
  13235. //***********validFrom**************/
  13236. c = 0;
  13237. loc = strstr(sLineWord, "validFrom");
  13238. if(loc != NULL)
  13239. {
  13240. memset(sstr ,0, sizeof(sstr) );
  13241. while (loc[3+strlen("validFrom")+c] != '\"')
  13242. {
  13243. sstr[c] = loc[3+strlen("validFrom")+c];
  13244. c++;
  13245. }
  13246. sstr[c] = '\0';
  13247. strcpy(tempvalidFromStr,sstr);
  13248. }
  13249. else
  13250. {
  13251. strcpy(tempvalidFromStr,"");
  13252. }
  13253. //***********validTo **************/
  13254. c = 0;
  13255. loc = strstr(sLineWord, "validTo");
  13256. if(loc != NULL)
  13257. {
  13258. memset(sstr ,0, sizeof(sstr) );
  13259. while (loc[3+strlen("validTo")+c] != '\"')
  13260. {
  13261. sstr[c] = loc[3+strlen("validTo")+c];
  13262. c++;
  13263. }
  13264. sstr[c] = '\0';
  13265. strcpy(tempvalidToStr,sstr);
  13266. }
  13267. else
  13268. {
  13269. strcpy(tempvalidToStr,"");
  13270. }
  13271. //***********duration**************/
  13272. c = 0;
  13273. loc = strstr(sLineWord, "duration");
  13274. if(loc != NULL)
  13275. {
  13276. memset(sstr ,0, sizeof(sstr) );
  13277. while (loc[2+strlen("duration")+c] != ',')
  13278. {
  13279. sstr[c] = loc[2+strlen("duration")+c];
  13280. c++;
  13281. }
  13282. sstr[c] = '\0';
  13283. tempdurationInt = atoi(sstr);
  13284. }
  13285. else
  13286. {
  13287. tempdurationInt = 0;
  13288. }
  13289. //**********startSchedule**********/
  13290. c = 0;
  13291. loc = strstr(sLineWord, "startSchedule");
  13292. memset(sstr ,0, sizeof(sstr) );
  13293. while (loc[3+strlen("startSchedule")+c] != '\"')
  13294. {
  13295. sstr[c] = loc[3+strlen("startSchedule")+c];
  13296. c++;
  13297. }
  13298. sstr[c] = '\0';
  13299. strcpy(tempstartScheduleStr, sstr);
  13300. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13301. //**********chargingRateUnit**********/
  13302. c = 0;
  13303. loc = strstr(sLineWord, "chargingRateUnit");
  13304. memset(sstr ,0, sizeof(sstr) );
  13305. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13306. {
  13307. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13308. c++;
  13309. }
  13310. sstr[c] = '\0';
  13311. strcpy(tempchargingRateUnitStr, sstr);
  13312. //**********minChargingRate*******/
  13313. c = 0;
  13314. loc = strstr(sLineWord, "minChargingRate");
  13315. if(loc != NULL)
  13316. {
  13317. memset(sstr ,0, sizeof(sstr) );
  13318. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13319. {
  13320. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13321. c++;
  13322. }
  13323. sstr[c] = '\0';
  13324. tempminChargingRateFloat = atof(sstr);
  13325. }
  13326. else
  13327. {
  13328. tempminChargingRateFloat = 0.0;
  13329. }
  13330. //
  13331. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13332. tp.tm_isdst = -1;
  13333. time_t utc = mktime(&tp);
  13334. time_t t = time(NULL);
  13335. diff_t = difftime(t, utc);
  13336. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13337. //parsing strings to words
  13338. i = 0;
  13339. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13340. loc = loc+3+strlen("chargingSchedulePeriod");
  13341. pch = strtok(loc ,"{");
  13342. while (pch != NULL)
  13343. {
  13344. strcpy(SchedulePeriodList[i], pch);
  13345. pch = strtok (NULL, "{");
  13346. i = i + 1;
  13347. }
  13348. n_SchedulePeriods = i;
  13349. for(int i=0;i<n_SchedulePeriods;i++)
  13350. {
  13351. //*************startPeriod****************/
  13352. c = 0;
  13353. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13354. memset(sstr ,0, sizeof(sstr) );
  13355. while (loc[strlen("startPeriod")+2+c] != ',')
  13356. {
  13357. sstr[c] = loc[strlen("startPeriod")+2+c];
  13358. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13359. c++;
  13360. }
  13361. sstr[c] = '\0';
  13362. tempStartPeriodInt = atoi(sstr);
  13363. //*************limit****************/
  13364. c = 0;
  13365. loc = strstr(SchedulePeriodList[i], "limit");
  13366. memset(sstr ,0, sizeof(sstr) );
  13367. while (loc[strlen("limit")+2+c] != ',')
  13368. {
  13369. sstr[c] = loc[strlen("limit")+2+c];
  13370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13371. c++;
  13372. }
  13373. sstr[c] = '\0';
  13374. tempLimitInt = atof(sstr);
  13375. //*************numberPhases****************/
  13376. c = 0;
  13377. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13378. memset(sstr ,0, sizeof(sstr) );
  13379. if(loc != NULL)
  13380. {
  13381. while (loc[strlen("numberPhases")+2+c] != '}')
  13382. {
  13383. sstr[c] = loc[strlen("numberPhases")+2+c];
  13384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13385. c++;
  13386. }
  13387. sstr[c] = '\0';
  13388. tempNumberPhasesInt = atoi(sstr);
  13389. }
  13390. else
  13391. {
  13392. tempNumberPhasesInt = 0;
  13393. }
  13394. if(j == 0)
  13395. {
  13396. ChargePointMaxProfile.Duration = tempdurationInt;
  13397. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13398. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13399. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13400. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13401. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13402. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13403. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13404. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13405. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13406. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13407. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13408. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13409. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13410. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13411. }
  13412. }
  13413. if(MinChargingRate < tempminChargingRateFloat)
  13414. {
  13415. MinChargingRate = tempminChargingRateFloat;
  13416. }
  13417. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13418. if(confirmPeriods < n_SchedulePeriods)
  13419. {
  13420. confirmPeriods = n_SchedulePeriods;
  13421. }
  13422. j = j + 1;
  13423. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13424. fclose(fptr1);
  13425. }// end else
  13426. }// the end of access file ChargePointMaxProfile
  13427. //****************************TxDefaultProfile************************************************/
  13428. #if 0
  13429. switch(gunindex + 1)
  13430. {
  13431. case 0:
  13432. strcpy(fname, TxDefaultProfile_0_JSON );
  13433. break;
  13434. case 1:
  13435. strcpy(fname, TxDefaultProfile_1_JSON );
  13436. break;
  13437. case 2:
  13438. strcpy(fname, TxDefaultProfile_2_JSON );
  13439. break;
  13440. default:
  13441. strcpy(fname, TxDefaultProfile_1_JSON );
  13442. break;
  13443. }
  13444. #endif
  13445. memset(fname, 0, sizeof fname);
  13446. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13447. TxDefaultProfileFileIsNull=TRUE;
  13448. if((access(fname,F_OK))!=-1)
  13449. {
  13450. fptr1 = fopen(fname, "r");
  13451. c = 0;
  13452. c = fgetc(fptr1);
  13453. //DEBUG_INFO("c:%d\n",c);
  13454. rewind(fptr1);
  13455. if(c == EOF)
  13456. {
  13457. DEBUG_INFO("\n End of file reached.");
  13458. TxDefaultProfileFileIsNull=TRUE;
  13459. fclose(fptr1);
  13460. }
  13461. else
  13462. {
  13463. TxDefaultProfileFileIsNull=FALSE;
  13464. while(fscanf(fptr1, "%s", word) != EOF)
  13465. {
  13466. if(strcmp(word, "chargingProfileId") == 0)
  13467. {
  13468. n_chargingProfile = n_chargingProfile + 1;
  13469. }
  13470. }
  13471. rewind(fptr1);
  13472. //search Charging Profile Element
  13473. int i = 0;
  13474. int j = 0;
  13475. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13476. {
  13477. #if 0
  13478. //***********connectorId****************/
  13479. c = 0;
  13480. loc = strstr(sLineWord, "connectorId");
  13481. memset(sstr ,0, sizeof(sstr) );
  13482. while (loc[strlen("connectorId")+2+c] != ',')
  13483. {
  13484. sstr[c] = loc[strlen("connectorId")+2+c];
  13485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13486. c++;
  13487. }
  13488. sstr[c] = '\0';
  13489. tempconnectorIdInt = atoi(sstr);
  13490. #endif
  13491. //***********chargingProfileId**************/
  13492. c = 0;
  13493. loc = strstr(sLineWord, "chargingProfileId");
  13494. //DEBUG_INFO("loc=%s\n",loc);
  13495. memset(sstr ,0, sizeof(sstr) );
  13496. if(loc != NULL)
  13497. {
  13498. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13499. {
  13500. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13502. c++;
  13503. }
  13504. sstr[c] = '\0';
  13505. tempchargingProfileId = atoi(sstr);
  13506. }
  13507. else
  13508. {
  13509. tempchargingProfileId = 0;
  13510. }
  13511. //***********stackLevel**************/
  13512. c = 0;
  13513. loc = strstr(sLineWord, "stackLevel");
  13514. //DEBUG_INFO("loc=%s\n",loc);
  13515. memset(sstr ,0, sizeof(sstr) );
  13516. if(loc != NULL)
  13517. {
  13518. while (loc[2+strlen("stackLevel")+c] != '\"')
  13519. {
  13520. sstr[c] = loc[2+strlen("stackLevel")+c];
  13521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13522. c++;
  13523. }
  13524. sstr[c] = '\0';
  13525. tempstackLevel = atoi(sstr);
  13526. }
  13527. else
  13528. {
  13529. tempstackLevel = 0;
  13530. }
  13531. //***********chargingProfilePurpose **************/
  13532. c = 0;
  13533. loc = strstr(sLineWord, "chargingProfilePurpose");
  13534. //DEBUG_INFO("loc=%s\n",loc);
  13535. memset(sstr ,0, sizeof(sstr) );
  13536. if(loc != NULL)
  13537. {
  13538. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13539. {
  13540. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13541. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13542. c++;
  13543. }
  13544. sstr[c] = '\0';
  13545. strcpy(tempchargingProfilePurposeStr,sstr);
  13546. }
  13547. else
  13548. {
  13549. strcpy(tempchargingProfilePurposeStr,"");
  13550. }
  13551. //***********chargingProfileKind **************/
  13552. c = 0;
  13553. loc = strstr(sLineWord, "chargingProfileKind");
  13554. //DEBUG_INFO("loc=%s\n",loc);
  13555. memset(sstr ,0, sizeof(sstr) );
  13556. if(loc != NULL)
  13557. {
  13558. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13559. {
  13560. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13561. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13562. c++;
  13563. }
  13564. sstr[c] = '\0';
  13565. strcpy(tempchargingProfileKindStr,sstr);
  13566. }
  13567. else
  13568. {
  13569. strcpy(tempchargingProfileKindStr,"");
  13570. }
  13571. //***********recurrencyKind **************/
  13572. c = 0;
  13573. loc = strstr(sLineWord, "recurrencyKind");
  13574. //DEBUG_INFO("loc=%s\n",loc);
  13575. memset(sstr ,0, sizeof(sstr) );
  13576. if(loc != NULL)
  13577. {
  13578. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13579. {
  13580. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13581. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13582. c++;
  13583. }
  13584. sstr[c] = '\0';
  13585. strcpy(temprecurrencyKindStr,sstr);
  13586. }
  13587. else
  13588. {
  13589. strcpy(temprecurrencyKindStr,"");
  13590. }
  13591. //***********validFrom**************/
  13592. c = 0;
  13593. loc = strstr(sLineWord, "validFrom");
  13594. if(loc != NULL)
  13595. {
  13596. memset(sstr ,0, sizeof(sstr) );
  13597. while (loc[3+strlen("validFrom")+c] != '\"')
  13598. {
  13599. sstr[c] = loc[3+strlen("validFrom")+c];
  13600. c++;
  13601. }
  13602. sstr[c] = '\0';
  13603. strcpy(tempvalidFromStr,sstr);
  13604. }
  13605. else
  13606. {
  13607. strcpy(tempvalidFromStr,"");
  13608. }
  13609. //***********validTo **************/
  13610. c = 0;
  13611. loc = strstr(sLineWord, "validTo");
  13612. if(loc != NULL)
  13613. {
  13614. memset(sstr ,0, sizeof(sstr) );
  13615. while (loc[3+strlen("validTo")+c] != '\"')
  13616. {
  13617. sstr[c] = loc[3+strlen("validTo")+c];
  13618. c++;
  13619. }
  13620. sstr[c] = '\0';
  13621. strcpy(tempvalidToStr,sstr);
  13622. }
  13623. else
  13624. {
  13625. strcpy(tempvalidToStr,"");
  13626. }
  13627. //***********duration**************/
  13628. c = 0;
  13629. loc = strstr(sLineWord, "duration");
  13630. if(loc != NULL)
  13631. {
  13632. memset(sstr ,0, sizeof(sstr) );
  13633. while (loc[2+strlen("duration")+c] != ',')
  13634. {
  13635. sstr[c] = loc[2+strlen("duration")+c];
  13636. c++;
  13637. }
  13638. sstr[c] = '\0';
  13639. tempdurationInt = atoi(sstr);
  13640. }
  13641. else
  13642. {
  13643. tempdurationInt = 0;
  13644. }
  13645. //**********startSchedule**********/
  13646. c = 0;
  13647. loc = strstr(sLineWord, "startSchedule");
  13648. memset(sstr ,0, sizeof(sstr) );
  13649. while (loc[3+strlen("startSchedule")+c] != '\"')
  13650. {
  13651. sstr[c] = loc[3+strlen("startSchedule")+c];
  13652. c++;
  13653. }
  13654. sstr[c] = '\0';
  13655. strcpy(tempstartScheduleStr, sstr);
  13656. strcpy(TxDefaultProfileScheduleStr, sstr);
  13657. //**********chargingRateUnit**********/
  13658. c = 0;
  13659. loc = strstr(sLineWord, "chargingRateUnit");
  13660. memset(sstr ,0, sizeof(sstr) );
  13661. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13662. {
  13663. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13664. c++;
  13665. }
  13666. sstr[c] = '\0';
  13667. strcpy(tempchargingRateUnitStr, sstr);
  13668. //**********minChargingRate*******/
  13669. c = 0;
  13670. loc = strstr(sLineWord, "minChargingRate");
  13671. if(loc != NULL)
  13672. {
  13673. memset(sstr ,0, sizeof(sstr) );
  13674. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13675. {
  13676. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13677. c++;
  13678. }
  13679. sstr[c] = '\0';
  13680. tempminChargingRateFloat = atof(sstr);
  13681. }
  13682. else
  13683. {
  13684. tempminChargingRateFloat = 0.0;
  13685. }
  13686. //
  13687. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13688. tp.tm_isdst = -1;
  13689. time_t utc = mktime(&tp);
  13690. time_t t = time(NULL);
  13691. diff_t = difftime(t, utc);
  13692. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13693. //parsing strings to words
  13694. i = 0;
  13695. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13696. loc = loc+3+strlen("chargingSchedulePeriod");
  13697. pch = strtok(loc ,"{");
  13698. while (pch != NULL)
  13699. {
  13700. strcpy(SchedulePeriodList[i], pch);
  13701. pch = strtok (NULL, "{");
  13702. i = i + 1;
  13703. }
  13704. n_SchedulePeriods = i;
  13705. for(int i=0;i<n_SchedulePeriods;i++)
  13706. {
  13707. //*************startPeriod****************/
  13708. c = 0;
  13709. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13710. memset(sstr ,0, sizeof(sstr) );
  13711. while (loc[strlen("startPeriod")+2+c] != ',')
  13712. {
  13713. sstr[c] = loc[strlen("startPeriod")+2+c];
  13714. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13715. c++;
  13716. }
  13717. sstr[c] = '\0';
  13718. tempStartPeriodInt = atoi(sstr);
  13719. //*************limit****************/
  13720. c = 0;
  13721. loc = strstr(SchedulePeriodList[i], "limit");
  13722. memset(sstr ,0, sizeof(sstr) );
  13723. while (loc[strlen("limit")+2+c] != ',')
  13724. {
  13725. sstr[c] = loc[strlen("limit")+2+c];
  13726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13727. c++;
  13728. }
  13729. sstr[c] = '\0';
  13730. tempLimitInt = atof(sstr);
  13731. //*************numberPhases****************/
  13732. c = 0;
  13733. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13734. memset(sstr ,0, sizeof(sstr) );
  13735. if(loc != NULL)
  13736. {
  13737. while (loc[strlen("numberPhases")+2+c] != '}')
  13738. {
  13739. sstr[c] = loc[strlen("numberPhases")+2+c];
  13740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13741. c++;
  13742. }
  13743. sstr[c] = '\0';
  13744. tempNumberPhasesInt = atoi(sstr);
  13745. }
  13746. else
  13747. {
  13748. tempNumberPhasesInt = 0;
  13749. }
  13750. if(j == 0)
  13751. {
  13752. TxDefaultProfile.Duration = tempdurationInt;
  13753. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13754. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13755. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13756. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13757. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13758. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13759. TxDefaultProfile_TEMP.TransactionId = 0;
  13760. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13761. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13762. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13763. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13764. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13765. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13766. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13767. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13768. }
  13769. else
  13770. {
  13771. //other stack level charging Profile
  13772. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13773. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13774. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13775. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13776. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13777. }
  13778. }
  13779. if(MinChargingRate < tempminChargingRateFloat)
  13780. {
  13781. MinChargingRate = tempminChargingRateFloat;
  13782. }
  13783. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13784. if(confirmPeriods < n_SchedulePeriods)
  13785. confirmPeriods = n_SchedulePeriods;
  13786. j = j + 1;
  13787. }
  13788. fclose(fptr1);
  13789. //Stacking Charging Profiles
  13790. for(int l=0; l <(j-1) ;l++)
  13791. {
  13792. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13793. {
  13794. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13795. {
  13796. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13797. {
  13798. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13799. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13800. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13801. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13802. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13803. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13804. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13805. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13806. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13807. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13808. }
  13809. else
  13810. {
  13811. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13812. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13813. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13814. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13815. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13816. }
  13817. }
  13818. }
  13819. }//end of Stacking Charging Profiles
  13820. }// end else
  13821. }// the end of ACCESS TxDefaultProfile
  13822. //****************************TxProfile************************************************/
  13823. #if 0
  13824. switch(gunindex + 1)
  13825. {
  13826. case 0:
  13827. break;
  13828. case 1:
  13829. strcpy(fname, TxProfile_1_JSON );
  13830. break;
  13831. case 2:
  13832. strcpy(fname, TxProfile_2_JSON );
  13833. break;
  13834. default:
  13835. strcpy(fname, TxProfile_1_JSON );
  13836. break;
  13837. }
  13838. #endif
  13839. memset(fname, 0, sizeof fname);
  13840. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13841. TxProfileIsNull=TRUE;
  13842. if((access(fname,F_OK))!=-1)
  13843. {
  13844. fptr1 = fopen(fname, "r");
  13845. c = 0;
  13846. c = fgetc(fptr1);
  13847. //DEBUG_INFO("c:%d\n",c);
  13848. rewind(fptr1);
  13849. if(c == EOF)
  13850. {
  13851. DEBUG_INFO("\n End of file reached.");
  13852. TxProfileIsNull=TRUE;
  13853. fclose(fptr1);
  13854. }
  13855. else
  13856. {
  13857. TxProfileIsNull=FALSE;
  13858. while(fscanf(fptr1, "%s", word) != EOF)
  13859. {
  13860. if(strcmp(word, "chargingProfileId") == 0)
  13861. {
  13862. n_chargingProfile = n_chargingProfile + 1;
  13863. }
  13864. }
  13865. rewind(fptr1);
  13866. //search Charging Profile Element
  13867. int i= 0;
  13868. int j= 0;
  13869. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13870. #if 0
  13871. /***********connectorId****************/
  13872. c = 0;
  13873. loc = strstr(sLineWord, "connectorId");
  13874. memset(sstr ,0, sizeof(sstr) );
  13875. while (loc[strlen("connectorId")+2+c] != ',')
  13876. {
  13877. sstr[c] = loc[strlen("connectorId")+2+c];
  13878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13879. c++;
  13880. }
  13881. sstr[c] = '\0';
  13882. tempconnectorIdInt = atoi(sstr);
  13883. #endif
  13884. //***********chargingProfileId**************/
  13885. c = 0;
  13886. loc = strstr(sLineWord, "chargingProfileId");
  13887. memset(sstr ,0, sizeof(sstr) );
  13888. if(loc != NULL)
  13889. {
  13890. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13891. {
  13892. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13894. c++;
  13895. }
  13896. sstr[c] = '\0';
  13897. tempchargingProfileId = atoi(sstr);
  13898. }
  13899. else
  13900. {
  13901. tempchargingProfileId = 0;
  13902. }
  13903. //***********transactionId **************/
  13904. c = 0;
  13905. loc = strstr(sLineWord, "transactionId");
  13906. //DEBUG_INFO("loc=%s\n",loc);
  13907. memset(sstr ,0, sizeof(sstr) );
  13908. if(loc != NULL)
  13909. {
  13910. while (loc[2+strlen("transactionId")+c] != '\"')
  13911. {
  13912. sstr[c] = loc[2+strlen("transactionId")+c];
  13913. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13914. c++;
  13915. }
  13916. sstr[c] = '\0';
  13917. temptransactionId = atoi(sstr);
  13918. }
  13919. else
  13920. {
  13921. temptransactionId = 0;
  13922. }
  13923. //***********stackLevel**************/
  13924. c = 0;
  13925. loc = strstr(sLineWord, "stackLevel");
  13926. //DEBUG_INFO("loc=%s\n",loc);
  13927. memset(sstr ,0, sizeof(sstr) );
  13928. if(loc != NULL)
  13929. {
  13930. while (loc[2+strlen("stackLevel")+c] != '\"')
  13931. {
  13932. sstr[c] = loc[2+strlen("stackLevel")+c];
  13933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13934. c++;
  13935. }
  13936. sstr[c] = '\0';
  13937. tempstackLevel = atoi(sstr);
  13938. }
  13939. else
  13940. {
  13941. tempstackLevel = 0;
  13942. }
  13943. //***********chargingProfilePurpose **************/
  13944. c = 0;
  13945. loc = strstr(sLineWord, "chargingProfilePurpose");
  13946. //DEBUG_INFO("loc=%s\n",loc);
  13947. memset(sstr ,0, sizeof(sstr) );
  13948. if(loc != NULL)
  13949. {
  13950. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13951. {
  13952. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13953. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13954. c++;
  13955. }
  13956. sstr[c] = '\0';
  13957. strcpy(tempchargingProfilePurposeStr,sstr);
  13958. }
  13959. else
  13960. {
  13961. strcpy(tempchargingProfilePurposeStr,"");
  13962. }
  13963. //***********chargingProfileKind **************/
  13964. c = 0;
  13965. loc = strstr(sLineWord, "chargingProfileKind");
  13966. //DEBUG_INFO("loc=%s\n",loc);
  13967. memset(sstr ,0, sizeof(sstr) );
  13968. if(loc != NULL)
  13969. {
  13970. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13971. {
  13972. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13974. c++;
  13975. }
  13976. sstr[c] = '\0';
  13977. strcpy(tempchargingProfileKindStr,sstr);
  13978. }
  13979. else
  13980. {
  13981. strcpy(tempchargingProfileKindStr,"");
  13982. }
  13983. //***********recurrencyKind **************/
  13984. c = 0;
  13985. loc = strstr(sLineWord, "recurrencyKind");
  13986. //DEBUG_INFO("loc=%s\n",loc);
  13987. memset(sstr ,0, sizeof(sstr) );
  13988. if(loc != NULL)
  13989. {
  13990. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13991. {
  13992. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13993. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13994. c++;
  13995. }
  13996. sstr[c] = '\0';
  13997. strcpy(temprecurrencyKindStr,sstr);
  13998. }
  13999. else
  14000. {
  14001. strcpy(temprecurrencyKindStr,"");
  14002. }
  14003. //***********validFrom**************/
  14004. c = 0;
  14005. loc = strstr(sLineWord, "validFrom");
  14006. if(loc != NULL)
  14007. {
  14008. memset(sstr ,0, sizeof(sstr) );
  14009. while (loc[3+strlen("validFrom")+c] != '\"')
  14010. {
  14011. sstr[c] = loc[3+strlen("validFrom")+c];
  14012. c++;
  14013. }
  14014. sstr[c] = '\0';
  14015. strcpy(tempvalidFromStr,sstr);
  14016. }
  14017. else
  14018. {
  14019. strcpy(tempvalidFromStr,"");
  14020. }
  14021. //***********validTo**************/
  14022. c = 0;
  14023. loc = strstr(sLineWord, "validTo");
  14024. if(loc != NULL)
  14025. {
  14026. memset(sstr ,0, sizeof(sstr) );
  14027. while (loc[3+strlen("validTo")+c] != '\"')
  14028. {
  14029. sstr[c] = loc[3+strlen("validTo")+c];
  14030. c++;
  14031. }
  14032. sstr[c] = '\0';
  14033. strcpy(tempvalidToStr,sstr);
  14034. }
  14035. else
  14036. {
  14037. strcpy(tempvalidToStr,"");
  14038. }
  14039. //***********duration**************/
  14040. c = 0;
  14041. loc = strstr(sLineWord, "duration");
  14042. //DEBUG_INFO("loc=%s\n",loc);
  14043. memset(sstr ,0, sizeof(sstr) );
  14044. if(loc != NULL)
  14045. {
  14046. while (loc[2+strlen("duration")+c] != '\"')
  14047. {
  14048. sstr[c] = loc[2+strlen("duration")+c];
  14049. c++;
  14050. }
  14051. sstr[c] = '\0';
  14052. tempdurationInt = atoi(sstr);
  14053. }
  14054. else
  14055. {
  14056. tempdurationInt = 0;
  14057. }
  14058. //**********startSchedule**********/
  14059. c = 0;
  14060. loc = strstr(sLineWord, "startSchedule");
  14061. memset(sstr ,0, sizeof(sstr) );
  14062. while (loc[3+strlen("startSchedule")+c] != '\"')
  14063. {
  14064. sstr[c] = loc[3+strlen("startSchedule")+c];
  14065. c++;
  14066. }
  14067. sstr[c] = '\0';
  14068. strcpy(tempstartScheduleStr, sstr);
  14069. strcpy(TxProfileScheduleStr, sstr);
  14070. //**********chargingRateUnit**********/
  14071. c = 0;
  14072. loc = strstr(sLineWord, "chargingRateUnit");
  14073. memset(sstr ,0, sizeof(sstr) );
  14074. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14075. {
  14076. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14077. c++;
  14078. }
  14079. sstr[c] = '\0';
  14080. strcpy(tempchargingRateUnitStr, sstr);
  14081. //**********minChargingRate*******/
  14082. c = 0;
  14083. loc = strstr(sLineWord, "minChargingRate");
  14084. if(loc != NULL)
  14085. {
  14086. memset(sstr ,0, sizeof(sstr) );
  14087. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14088. {
  14089. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14090. c++;
  14091. }
  14092. sstr[c] = '\0';
  14093. tempminChargingRateFloat = atof(sstr);
  14094. }
  14095. else
  14096. {
  14097. tempminChargingRateFloat = 0.0;
  14098. }
  14099. //
  14100. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14101. tp.tm_isdst = -1;
  14102. time_t utc = mktime(&tp);
  14103. time_t t = time(NULL);
  14104. diff_t = difftime(t, utc);
  14105. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14106. //parsing strings to words
  14107. i = 0;
  14108. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14109. loc = loc+3+strlen("chargingSchedulePeriod");
  14110. pch = strtok(loc ,"{");
  14111. while (pch != NULL)
  14112. {
  14113. strcpy(SchedulePeriodList[i], pch);
  14114. pch = strtok (NULL, "{");
  14115. i = i + 1;
  14116. }
  14117. n_SchedulePeriods = i;
  14118. for(int i=0;i<n_SchedulePeriods;i++)
  14119. {
  14120. //*************startPeriod****************/
  14121. c = 0;
  14122. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14123. memset(sstr ,0, sizeof(sstr) );
  14124. while (loc[strlen("startPeriod")+2+c] != ',')
  14125. {
  14126. sstr[c] = loc[strlen("startPeriod")+2+c];
  14127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14128. c++;
  14129. }
  14130. sstr[c] = '\0';
  14131. tempStartPeriodInt = atoi(sstr);
  14132. //*************limit****************/
  14133. c = 0;
  14134. loc = strstr(SchedulePeriodList[i], "limit");
  14135. memset(sstr ,0, sizeof(sstr) );
  14136. while (loc[strlen("limit")+2+c] != ',')
  14137. {
  14138. sstr[c] = loc[strlen("limit")+2+c];
  14139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14140. c++;
  14141. }
  14142. sstr[c] = '\0';
  14143. tempLimitInt = atof(sstr);
  14144. //*************numberPhases****************/
  14145. c = 0;
  14146. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14147. memset(sstr ,0, sizeof(sstr) );
  14148. if(loc != NULL)
  14149. {
  14150. while (loc[strlen("numberPhases")+2+c] != '}')
  14151. {
  14152. sstr[c] = loc[strlen("numberPhases")+2+c];
  14153. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14154. c++;
  14155. }
  14156. sstr[c] = '\0';
  14157. tempNumberPhasesInt = atoi(sstr);
  14158. }
  14159. else
  14160. {
  14161. tempNumberPhasesInt = 0;
  14162. }
  14163. //TxProfile.Duration = durationInt;
  14164. TxProfile.TotalPeriod = n_SchedulePeriods;
  14165. TxProfile.Period[i].Limit = tempLimitInt;
  14166. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14167. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14168. }
  14169. if(MinChargingRate < tempminChargingRateFloat)
  14170. {
  14171. MinChargingRate = tempminChargingRateFloat;
  14172. }
  14173. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14174. if(confirmPeriods < n_SchedulePeriods)
  14175. confirmPeriods = n_SchedulePeriods;
  14176. if(j == 0)
  14177. {
  14178. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14179. TxProfile_TEMP.StackLevel = tempstackLevel;
  14180. TxProfile_TEMP.TransactionId = 0;
  14181. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14182. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14183. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14184. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14185. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14186. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14187. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14188. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14189. }
  14190. }
  14191. fclose(fptr1);
  14192. }
  14193. }// the end of ACCESS TxProfile
  14194. //-----------------------------------------------CompositeSchedule--------------------------//
  14195. int period=0;
  14196. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14197. {
  14198. //TxProfile
  14199. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14200. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14201. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14202. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14203. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14204. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14209. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14210. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14211. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14212. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14213. {
  14214. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14215. {
  14216. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14217. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14218. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14219. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14220. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14221. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14222. period = period + 1;
  14223. }
  14224. else
  14225. {
  14226. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14227. {
  14228. }
  14229. else
  14230. {
  14231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14233. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14234. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14235. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14236. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14237. period = period + 1;
  14238. }
  14239. }
  14240. }
  14241. struct tm tp;
  14242. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14243. tp.tm_isdst = -1;
  14244. time_t utc = mktime(&tp);
  14245. time_t t = time(NULL);
  14246. double diff_f = difftime(t, utc);
  14247. int diff_i;// = (int)diff_f;
  14248. int quotient; // = diff_i / 86400;//86400 seconds/day
  14249. if(diff_f >= 0)
  14250. {
  14251. diff_i = (int)diff_f;
  14252. quotient = diff_i / 86400;//86400 seconds/day
  14253. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14254. {
  14255. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14256. {
  14257. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14258. {
  14259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14260. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14261. }
  14262. else
  14263. {
  14264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14265. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14266. }
  14267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14269. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14270. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14271. period = period + 1;
  14272. }
  14273. }
  14274. }// end of if(diff_f >= 0)
  14275. }
  14276. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14277. {
  14278. //TxDefaultProfile
  14279. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14280. struct tm tp;
  14281. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14282. tp.tm_isdst = -1;
  14283. time_t utc = mktime(&tp);
  14284. time_t t = time(NULL);
  14285. double diff_f = difftime(t, utc);
  14286. int diff_i;// = (int)diff_f;
  14287. int quotient; // = diff_i / 86400;//86400 seconds/day
  14288. int remainder;
  14289. //---- Define StartSchedule----/
  14290. struct tm *gtime;
  14291. time_t now;
  14292. char buf[28];
  14293. //---Read the current system time---/
  14294. time(&now);
  14295. //---Convert the system time to GMT (now UTC)---/
  14296. gtime = gmtime(&now);
  14297. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14298. if(diff_f >= 0)
  14299. {
  14300. diff_i = (int)diff_f;
  14301. quotient = diff_i / 86400;//86400 seconds/day
  14302. remainder = diff_i % 86400;
  14303. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14304. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14305. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14306. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14308. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14309. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14310. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14311. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14315. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14316. {
  14317. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14318. {
  14319. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14320. {
  14321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14323. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14324. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14325. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14326. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14327. period = period + 1;
  14328. }
  14329. else
  14330. {
  14331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14334. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14335. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14336. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14337. period = period + 1;
  14338. }
  14339. }
  14340. }
  14341. } // end of diff_f >= 0
  14342. }
  14343. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14344. {
  14345. //TxDefaultProfile
  14346. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14347. struct tm tp;
  14348. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14349. tp.tm_isdst = -1;
  14350. time_t utc = mktime(&tp);
  14351. time_t t = time(NULL);
  14352. double diff_f = difftime(t, utc);
  14353. int diff_i;// = (int)diff_f;
  14354. int quotient; // = diff_i / 86400;//86400 seconds/day
  14355. int remainder;
  14356. //---- Define StartSchedule----/
  14357. struct tm *gtime;
  14358. time_t now;
  14359. char buf[28];
  14360. //---Read the current system time---/
  14361. time(&now);
  14362. //---Convert the system time to GMT (now UTC)---/
  14363. gtime = gmtime(&now);
  14364. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14365. if(diff_f >= 0)
  14366. {
  14367. diff_i = (int)diff_f;
  14368. quotient = diff_i / 86400;//86400 seconds/day
  14369. remainder = diff_i % 86400;
  14370. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14371. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14372. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14375. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14376. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14377. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14378. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14379. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14380. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14381. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14382. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14383. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14384. {
  14385. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14386. {
  14387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14390. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14391. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14392. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14393. period = period + 1;
  14394. }
  14395. }
  14396. } //end of diff_f >= 0
  14397. }
  14398. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14399. {
  14400. //ChargePointMaxProfile
  14401. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14403. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14404. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14407. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14408. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14409. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14410. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14411. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14412. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14413. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14414. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14415. {
  14416. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14417. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14418. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14419. period = period + 1;
  14420. }
  14421. }
  14422. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14423. {
  14424. //TxProfile Daily
  14425. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14426. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14427. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14428. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14429. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14430. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14431. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14432. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14433. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14434. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14435. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14436. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14437. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14438. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14439. {
  14440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14443. }
  14444. }
  14445. confirmPeriods = period;
  14446. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14447. 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,"
  14448. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14449. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14450. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14451. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14452. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14453. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14454. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14455. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14456. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14457. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14459. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14460. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14463. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14464. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14465. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14467. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14468. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14469. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14470. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14471. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14472. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14473. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14474. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14475. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14476. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14477. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14483. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14495. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14497. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14498. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14499. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14500. }
  14501. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14502. {
  14503. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14504. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14505. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14506. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14507. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14508. }
  14509. int GetWebSocketPingInterval(void)
  14510. {
  14511. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14512. }
  14513. int GetInternetConn(void)
  14514. {
  14515. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14516. }
  14517. void LWS_Send(char * str)
  14518. {
  14519. //=====================================================
  14520. // Check InternetConn 0: disconnected, 1: connected
  14521. //====================================================
  14522. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14523. {
  14524. DEBUG_INFO("\n offline now !!!\n");
  14525. return;
  14526. }
  14527. pthread_mutex_lock(&lock);
  14528. memset(SendBuffer,0,SendBufLen);
  14529. sprintf((char *)SendBuffer, "%s", str);
  14530. pthread_mutex_unlock(&lock);
  14531. lws_callback_on_writable(wsi_client);
  14532. lws_service(context, 10000);//timeout_ms
  14533. }