MessageHandler.c 613 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966
  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. static int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. static 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. server_sign = FALSE;
  904. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  905. {
  906. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  907. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  910. }
  911. // Charger PRE_SYS_MODE
  912. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  913. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  914. clientTime.Heartbeat=time((time_t*)NULL);
  915. #if 0
  916. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  917. {
  918. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  919. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  920. }
  921. #endif
  922. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  923. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  924. // allocate Configuration memory address
  925. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  930. {
  931. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  932. DEBUG_INFO("DC ...\n");
  933. }
  934. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  935. {
  936. SystemInitial = AC_QUANTITY;
  937. DEBUG_INFO("AC ...\n");
  938. }
  939. //Status / ConnectorPlugIn Setting
  940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  941. {
  942. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  943. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  944. }
  945. for (int index = 0; index < CCS_QUANTITY; index++)
  946. {
  947. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  948. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  949. }
  950. for (int index = 0; index < GB_QUANTITY; index++)
  951. {
  952. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  953. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  954. }
  955. for (int index = 0; index < AC_QUANTITY; index++)
  956. {
  957. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  958. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  959. }
  960. return result;
  961. }
  962. int ProcessShareMemory()
  963. {
  964. if(InitShareMemory() == FAIL)
  965. {
  966. #ifdef SystemLogMessage
  967. DEBUG_ERROR("InitShareMemory NG\n");
  968. #endif
  969. if(ShmStatusCodeData!=NULL)
  970. {
  971. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  972. }
  973. sleep(5);
  974. return FAIL;
  975. }
  976. return PASS;
  977. }
  978. //---------------------------------------------
  979. // new:
  980. // enum SYSTEM_STATUS
  981. // {
  982. // SYS_MODE_BOOTING = 0,
  983. // SYS_MODE_IDLE = 1,
  984. // SYS_MODE_AUTHORIZING = 2,
  985. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  986. // SYS_MODE_REASSIGN = 4,
  987. // SYS_MODE_PREPARING = 5,
  988. // SYS_MODE_PREPARE_FOR_EV = 6,
  989. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  990. // SYS_MODE_CHARGING = 8,
  991. // SYS_MODE_TERMINATING = 9,
  992. // SYS_MODE_COMPLETE = 10,
  993. // SYS_MODE_ALARM = 11,
  994. // SYS_MODE_FAULT = 12,
  995. // SYS_MODE_RESERVATION = 13,
  996. // SYS_MODE_BOOKING = 14,
  997. // SYS_MODE_MAINTAIN = 15,
  998. // SYS_MODE_DEBUG = 16,
  999. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1000. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1001. // SYS_MODE_UPDATE = 19
  1002. // };
  1003. //
  1004. //
  1005. //-----------------------------------------
  1006. void CheckSystemValue(void)
  1007. {
  1008. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1009. //int IdleModeCnt = 0;
  1010. char filenmae[100]={0};
  1011. char str[100]={0};
  1012. //===============================
  1013. // send Heartbeat
  1014. //===============================
  1015. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1016. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1017. {
  1018. printf("Heartbeat !!!\n");
  1019. //parameter for test
  1020. sendHeartbeatRequest(0);
  1021. //==============================================
  1022. // Reset Waiting Time
  1023. //==============================================
  1024. clientTime.Heartbeat=time((time_t*)NULL);
  1025. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1026. }
  1027. else if((server_sign == TRUE) &&(FirstHeartBeat == 0)) // Send First HeartBeat
  1028. {
  1029. printf("Heartbeat !!!\n");
  1030. //parameter for test
  1031. sendHeartbeatRequest(0);
  1032. //==============================================
  1033. // Reset Waiting Time
  1034. //==============================================
  1035. clientTime.Heartbeat=time((time_t*)NULL);
  1036. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1037. }
  1038. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1039. {
  1040. //===============================
  1041. // CSU Trigger Reset Conf
  1042. //===============================
  1043. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1044. {
  1045. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1046. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1047. {
  1048. server_sign = FALSE;
  1049. }
  1050. }
  1051. //===============================
  1052. // CSU Trigger Authorize Request
  1053. //===============================
  1054. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1055. {
  1056. sendAuthorizeRequest(0);
  1057. authorizeRetryTimes = authorizeRetryTimes + 1;
  1058. if(authorizeRetryTimes < 3)
  1059. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1060. }
  1061. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1062. {
  1063. authorizeRetryTimes = 0;
  1064. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1065. server_sign = FALSE;
  1066. }
  1067. 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))
  1068. {
  1069. sendAuthorizeRequest(0);
  1070. }
  1071. //===============================
  1072. // CSU Trigger Smart Charging Profilw
  1073. //===============================
  1074. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1075. {
  1076. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1077. GetChargingProfileRequest(gun_index);
  1078. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1079. }
  1080. //==============================================
  1081. // Charger start transaction
  1082. //==============================================
  1083. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1084. {
  1085. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1086. sendStartTransactionRequest(gun_index);
  1087. clientTime.StartTransaction = time((time_t*)NULL);
  1088. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1089. }
  1090. //==============================================
  1091. // Charger stop transaction
  1092. //==============================================
  1093. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1094. {
  1095. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1096. sendStopTransactionRequest(gun_index);
  1097. clientTime.StopTransaction = time((time_t*)NULL);
  1098. }
  1099. //==============================================
  1100. // Charger status report
  1101. //==============================================
  1102. /* Check Mode Change */
  1103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1104. {
  1105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1106. {
  1107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1108. {
  1109. 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]*/ )
  1110. {
  1111. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1112. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1113. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1114. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1115. statusModeChage[gun_index] = TRUE;
  1116. }
  1117. }
  1118. }
  1119. for (int index = 0; index < CCS_QUANTITY; index++)
  1120. {
  1121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1122. {
  1123. 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]*/ )
  1124. {
  1125. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1126. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1127. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1128. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1129. statusModeChage[gun_index] = TRUE;
  1130. }
  1131. }
  1132. }
  1133. for (int index = 0; index < GB_QUANTITY; index++)
  1134. {
  1135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1136. {
  1137. 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]*/ )
  1138. {
  1139. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1140. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1141. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1143. statusModeChage[gun_index] = TRUE;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else //AC
  1149. {
  1150. for (int index = 0; index < AC_QUANTITY; index++)
  1151. {
  1152. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1153. {
  1154. 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]*/ )
  1155. {
  1156. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1157. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1158. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }// END OF FOR
  1164. }// END OF ELSE
  1165. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1166. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1167. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1168. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1169. {
  1170. if(SystemInitial != 0)
  1171. SystemInitial = SystemInitial -1;
  1172. sendStatusNotificationRequest(gun_index);
  1173. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1174. statusModeChage[gun_index] = FALSE;
  1175. }
  1176. //==============================================
  1177. // Meter report
  1178. //==============================================
  1179. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1180. {
  1181. //check Transaction active
  1182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1183. {
  1184. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1185. {
  1186. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1187. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1188. {
  1189. meterValueSend[gun_index] =1;
  1190. }
  1191. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1192. {
  1193. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1194. if((access(filenmae,F_OK))!=-1)
  1195. {
  1196. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1197. sprintf(str,"rm -f %s",filenmae);
  1198. system(str);
  1199. }
  1200. }
  1201. }// End for CHAdeMO
  1202. for (int index = 0; index < CCS_QUANTITY; index++)
  1203. {
  1204. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1205. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1206. {
  1207. meterValueSend[gun_index] =1;
  1208. }
  1209. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1210. {
  1211. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1212. if((access(filenmae,F_OK))!=-1)
  1213. {
  1214. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1215. sprintf(str,"rm -f %s",filenmae);
  1216. system(str);
  1217. }
  1218. }
  1219. } // End for CCS
  1220. for (int index = 0; index < GB_QUANTITY; index++)
  1221. {
  1222. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1223. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1224. {
  1225. meterValueSend[gun_index] =1;
  1226. }
  1227. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1228. {
  1229. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1230. if((access(filenmae,F_OK))!=-1)
  1231. {
  1232. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1233. sprintf(str,"rm -f %s",filenmae);
  1234. system(str);
  1235. }
  1236. }
  1237. }// End for GB
  1238. }
  1239. else
  1240. {
  1241. for (int index = 0; index < AC_QUANTITY; index++)
  1242. {
  1243. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1244. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1245. {
  1246. meterValueSend[gun_index] =1;
  1247. }
  1248. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1249. {
  1250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1251. if((access(filenmae,F_OK))!=-1)
  1252. {
  1253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1254. sprintf(str,"rm -f %s",filenmae);
  1255. system(str);
  1256. }
  1257. }
  1258. }//End for AC
  1259. }//END OF ELSE
  1260. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1261. if(meterValueSend[gun_index] == 1)
  1262. sendMeterValuesRequest(gun_index);
  1263. }
  1264. //==============================================
  1265. // Check Connector reserved
  1266. //==============================================
  1267. //===============================
  1268. // Check if Reserve is expired
  1269. //===============================
  1270. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1271. {
  1272. double diff_t;
  1273. struct tm tp;
  1274. // current time
  1275. time_t t = time(NULL);
  1276. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1277. tp.tm_isdst = -1;
  1278. time_t utc = mktime(&tp);
  1279. diff_t = difftime(utc, t);
  1280. if(diff_t <= 0)
  1281. {
  1282. DEBUG_INFO("reserve expired !!! \n");
  1283. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1284. }
  1285. }//END OF Check if Reserve is expired
  1286. //==========================================
  1287. // csu trigger FirmwareStatusNotificationReq
  1288. //==========================================
  1289. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1290. {
  1291. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1292. }
  1293. //==========================================
  1294. // csu trigger CancelReservationConf
  1295. //==========================================
  1296. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1297. {
  1298. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1299. }
  1300. //==========================================
  1301. // csu trigger ChangeAvailabilityConf
  1302. //==========================================
  1303. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1304. {
  1305. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1306. }
  1307. //==========================================
  1308. // csu trigger UnlockConnectorConf
  1309. //==========================================
  1310. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1311. {
  1312. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1313. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1314. }
  1315. //==========================================
  1316. // csu trigger ReserveNowConf
  1317. //==========================================
  1318. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1319. {
  1320. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1321. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1322. }
  1323. //==========================================
  1324. // csu trigger DataTransferReq
  1325. //==========================================
  1326. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1327. {
  1328. sendDataTransferRequest(gun_index);
  1329. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1330. }
  1331. }
  1332. }
  1333. //==========================================
  1334. // send request routine
  1335. //==========================================
  1336. int sendAuthorizeRequest(int gun_index)
  1337. {
  1338. mtrace();
  1339. int result = FAIL;
  1340. char message[100]={0};
  1341. char guid[37];
  1342. char tempdata[65]={0};
  1343. DEBUG_INFO("sendAuthorizeRequest \n");
  1344. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1345. //Local Authorize
  1346. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1347. {
  1348. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1349. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1350. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1351. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1352. result = PASS;
  1353. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1354. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1355. authorizeRetryTimes = 0;
  1356. return result;
  1357. }
  1358. 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))||
  1359. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1360. {
  1361. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1362. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1363. {
  1364. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1365. {
  1366. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1367. }
  1368. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1369. {
  1370. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1371. }
  1372. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1373. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1374. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1376. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1377. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1378. authorizeRetryTimes = 0;
  1379. return result;
  1380. }
  1381. else
  1382. {
  1383. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1384. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1385. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1387. result = PASS;
  1388. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1389. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1390. authorizeRetryTimes = 0;
  1391. return result;
  1392. }
  1393. }
  1394. //initailize struct Authorize
  1395. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1396. //get data from shared memory
  1397. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1398. random_uuid(guid);
  1399. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1400. LWS_Send(message);
  1401. sprintf(tempdata, "Authorize,%d", gun_index);
  1402. if(hashmap_operation(0, guid, tempdata) == 1)
  1403. {
  1404. result = PASS;
  1405. DEBUG_ERROR("Authorize mapItem pass\n");
  1406. }
  1407. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1408. return result;
  1409. }
  1410. int sendBootNotificationRequest(void)
  1411. {
  1412. mtrace();
  1413. int result = FAIL;
  1414. char message[500]={0}, payload[700]={0};
  1415. char guid[37]={0};
  1416. char tempdata[65]={0};
  1417. int IsGunCharging = FALSE;
  1418. //check Transaction active
  1419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1420. {
  1421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1422. {
  1423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1424. {
  1425. IsGunCharging = TRUE;
  1426. }
  1427. }
  1428. for (int index = 0; index < CCS_QUANTITY; index++)
  1429. {
  1430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1431. {
  1432. IsGunCharging = TRUE;
  1433. }
  1434. }
  1435. for (int index = 0; index < GB_QUANTITY; index++)
  1436. {
  1437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1438. {
  1439. IsGunCharging = TRUE;
  1440. }
  1441. }
  1442. }
  1443. else
  1444. {
  1445. for (int index = 0; index < AC_QUANTITY; index++)
  1446. {
  1447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1448. {
  1449. IsGunCharging = TRUE;
  1450. }
  1451. }
  1452. }
  1453. if(IsGunCharging == TRUE)
  1454. {
  1455. server_sign = TRUE;
  1456. return result;
  1457. }
  1458. // Fill BootNotification fields
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1461. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1462. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1463. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1464. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1465. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1466. #if 0
  1467. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1468. ShmOCPP16Data->ChargeBoxId
  1469. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1470. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1471. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1472. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1473. ,ShmOCPP16Data->BootNotification.CpIccid
  1474. ,ShmOCPP16Data->BootNotification.CpImsi
  1475. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1476. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1477. #endif
  1478. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1479. ShmOCPP16Data->ChargeBoxId
  1480. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1481. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1482. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1483. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1484. ,ShmOCPP16Data->BootNotification.CpIccid
  1485. ,ShmOCPP16Data->BootNotification.CpImsi);
  1486. random_uuid(guid);
  1487. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1488. LWS_Send(message);
  1489. sprintf(tempdata, "BootNotification,0");
  1490. 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*/)
  1491. {
  1492. result = PASS;
  1493. }
  1494. memset(queuedata, 0, sizeof(queuedata));
  1495. strcpy(queuedata,message);
  1496. return result;
  1497. }
  1498. int sendDataTransferRequest(int gun_index)
  1499. {
  1500. mtrace();
  1501. char message[1000]={0};
  1502. char guid[37]={0};
  1503. char tempdata[65]={0};
  1504. int result = FAIL;
  1505. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1506. random_uuid(guid);
  1507. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1508. MESSAGE_TYPE_CALL,
  1509. guid,
  1510. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1511. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1512. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1513. LWS_Send(message);
  1514. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1515. 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*/)
  1516. {
  1517. result = PASS;
  1518. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1519. }
  1520. return result;
  1521. }
  1522. int sendDiagnosticsStatusNotificationRequest(char *status)
  1523. {
  1524. mtrace();
  1525. int result = FAIL;
  1526. char message[110]={0};
  1527. char guid[37]={0};
  1528. char tempdata[65]={0};
  1529. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1530. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1531. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1532. random_uuid(guid);
  1533. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1534. LWS_Send(message);
  1535. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1536. if(hashmap_operation(0, guid, tempdata) == 1)
  1537. {
  1538. result = PASS;
  1539. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1540. }
  1541. //#ifdef SystemLogMessage
  1542. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1543. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1544. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1545. //#endif
  1546. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1547. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1548. //record status
  1549. if(strcmp(status,"Idle")==0)
  1550. {
  1551. DiagnosticsStatusNotificationStatus = 0;
  1552. }
  1553. else if(strcmp(status,"Uploaded")==0)
  1554. {
  1555. DiagnosticsStatusNotificationStatus = 1;
  1556. }
  1557. else if(strcmp(status,"UploadFailed")==0)
  1558. {
  1559. DiagnosticsStatusNotificationStatus = 2;
  1560. }
  1561. else if(strcmp(status,"Uploading")==0)
  1562. {
  1563. DiagnosticsStatusNotificationStatus = 3;
  1564. }
  1565. return result;
  1566. }
  1567. int sendFirmwareStatusNotificationRequest(char *status)
  1568. {
  1569. mtrace();
  1570. int result = FAIL;
  1571. char message[110]={0};
  1572. char guid[37]={0};
  1573. char tempdata[65]={0};
  1574. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1575. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1576. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1577. random_uuid(guid);
  1578. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1579. LWS_Send(message);
  1580. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1581. 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*/)
  1582. {
  1583. result = PASS;
  1584. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1585. }
  1586. //#ifdef SystemLogMessage
  1587. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1588. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1589. //#endif
  1590. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1591. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1592. //record status
  1593. if(strcmp(status,"Downloaded")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 0;
  1596. }
  1597. else if(strcmp(status,"DownloadFailed")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 1;
  1600. }
  1601. else if(strcmp(status,"Downloading")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 2;
  1604. }
  1605. else if(strcmp(status,"Idle")==0)
  1606. {
  1607. FirmwareStatusNotificationStatus = 3;
  1608. }
  1609. else if(strcmp(status,"InstallationFailed")==0)
  1610. {
  1611. FirmwareStatusNotificationStatus = 4;
  1612. }
  1613. else if(strcmp(status,"Installing")==0)
  1614. {
  1615. FirmwareStatusNotificationStatus = 5;
  1616. }
  1617. else if(strcmp(status,"Installed")==0)
  1618. {
  1619. FirmwareStatusNotificationStatus = 6;
  1620. }
  1621. return result;
  1622. }
  1623. int sendHeartbeatRequest(int gun_index)
  1624. {
  1625. mtrace();
  1626. int result = FAIL;
  1627. char message[80]={0};
  1628. char guid[37]={0};
  1629. char tempdata[65]={0};
  1630. random_uuid(guid);
  1631. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1632. , MESSAGE_TYPE_CALL
  1633. , guid );
  1634. LWS_Send(message);
  1635. sprintf(tempdata, "Heartbeat,%d", 0);
  1636. 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*/)
  1637. {
  1638. result = PASS;
  1639. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1640. }
  1641. return result;
  1642. }
  1643. int sendStartTransactionRequest(int gun_index)
  1644. {
  1645. mtrace();
  1646. int result = FAIL;
  1647. char message[250]={0};
  1648. char guid[37]={0};
  1649. struct timeval tmnow;
  1650. struct tm *tm;
  1651. char buf[28];//, usec_buf[6];
  1652. char tempdata[65]={0};
  1653. DEBUG_INFO("sendStartTransactionRequest...");
  1654. gettimeofday(&tmnow, NULL);
  1655. time_t t;
  1656. t = time(NULL);
  1657. /*UTC time and date*/
  1658. tm = gmtime(&t);
  1659. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1660. #if 0 // remove temporally
  1661. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1662. strcat(buf,".");
  1663. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1664. strcat(buf,usec_buf);
  1665. #endif
  1666. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1667. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1668. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1669. // clear StartTransaction Response
  1670. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1671. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1672. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1673. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1675. {
  1676. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1677. {
  1678. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1679. {
  1680. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1681. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1682. }
  1683. }
  1684. for (int index = 0; index < CCS_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. for (int index = 0; index < GB_QUANTITY; index++)
  1693. {
  1694. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1695. {
  1696. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1697. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1698. }
  1699. }
  1700. }
  1701. else
  1702. {
  1703. for (int index = 0; index < AC_QUANTITY; index++)
  1704. {
  1705. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1706. {
  1707. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1708. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1709. }
  1710. }
  1711. }//END OF ELSE
  1712. random_uuid(guid);
  1713. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1714. , MESSAGE_TYPE_CALL
  1715. , guid
  1716. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1717. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1718. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1719. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1720. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1721. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1722. 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*/)
  1723. {
  1724. result = PASS;
  1725. }
  1726. strcpy(queuedata, message);
  1727. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1728. if(GetTransactionQueueNum() == 1)
  1729. {
  1730. LWS_Send(message);
  1731. }
  1732. #if 0
  1733. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1734. 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*/)
  1735. {
  1736. result = PASS;
  1737. }
  1738. strcpy(queuedata, message);
  1739. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1740. #endif
  1741. //#ifdef SystemLogMessage
  1742. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1743. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1744. //#endif
  1745. return result;
  1746. }
  1747. int sendStatusNotificationRequest(int gun_index)
  1748. {
  1749. mtrace();
  1750. int result = FAIL;
  1751. char message[600]={0};
  1752. char guid[37];
  1753. int currentStatus = 0;
  1754. struct timeval tmnow;
  1755. struct tm *tm;
  1756. char buf[28];//, usec_buf[6];
  1757. char tempdata[65]={0};
  1758. gettimeofday(&tmnow, NULL);
  1759. time_t t;
  1760. t = time(NULL);
  1761. /*UTC time and date*/
  1762. tm = gmtime(&t);
  1763. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1764. #if 0 // remove temporally
  1765. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1766. strcat(buf,".");
  1767. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1768. strcat(buf,usec_buf);
  1769. #endif
  1770. printf("%s",buf);
  1771. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1772. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1773. // it's option
  1774. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1775. /*
  1776. enum _SYSTEM_STATUS
  1777. {
  1778. S_BOOTING = 0,
  1779. S_IDLE, = 1
  1780. S_AUTHORIZING, =2
  1781. S_REASSIGN_CHECK, =3
  1782. S_REASSIGN, =4
  1783. S_PRECHARGE, =5
  1784. S_PREPARING_FOR_EV, =6
  1785. S_PREPARING_FOR_EVSE, =7
  1786. S_CHARGING, =8
  1787. S_TERMINATING, =9
  1788. S_COMPLETE, =10
  1789. S_ALARM, =11
  1790. S_FAULT =12
  1791. }
  1792. */
  1793. //check Transaction active
  1794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1795. {
  1796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1797. {
  1798. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1799. {
  1800. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1801. {
  1802. currentStatus = 1; //OCPP Status: Preparing
  1803. }
  1804. else
  1805. {
  1806. currentStatus = 0; //OCPP Status: Available
  1807. }
  1808. }
  1809. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1810. {
  1811. currentStatus = 1; //OCPP Status: Preparing
  1812. }
  1813. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1814. {
  1815. currentStatus = 2; //OCPP Status: Charging
  1816. }
  1817. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1818. {
  1819. currentStatus = 5; //OCPP Status: Finishing
  1820. }
  1821. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1822. {
  1823. currentStatus = 4; //OCPP Status: SuspendedEV
  1824. }
  1825. 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
  1826. {
  1827. currentStatus = 7; //OCPP Status: Unavailable
  1828. }
  1829. 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
  1830. {
  1831. currentStatus = 8; //OCPP Status: Faulted
  1832. }
  1833. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1834. {
  1835. currentStatus = 6; //OCPP Status: Reserved
  1836. }
  1837. }//end of for CHAdeMO_QUANTITY
  1838. for (int index = 0; index < CCS_QUANTITY; index++)
  1839. {
  1840. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1841. {
  1842. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1843. {
  1844. currentStatus = 1; //OCPP Status: Preparing
  1845. }
  1846. else
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. }
  1851. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1852. {
  1853. currentStatus = 1; //OCPP Status: Preparing
  1854. }
  1855. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1856. {
  1857. currentStatus = 2; //OCPP Status: Charging
  1858. }
  1859. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1860. {
  1861. currentStatus = 5; //OCPP Status: Finishing
  1862. }
  1863. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //S_TERMINATING ---> SuspendedEV
  1864. {
  1865. currentStatus = 4; //OCPP Status: SuspendedEV
  1866. }
  1867. 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
  1868. {
  1869. currentStatus = 7; //OCPP Status : Unavailable
  1870. }
  1871. 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
  1872. {
  1873. currentStatus = 8; //OCPP Status: Faulted
  1874. }
  1875. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1876. {
  1877. currentStatus = 6; //OCPP Status: Reserved
  1878. }
  1879. }
  1880. for (int index = 0; index < GB_QUANTITY; index++)
  1881. {
  1882. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1883. {
  1884. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1885. {
  1886. currentStatus = 1; //OCPP Status: Preparing
  1887. }
  1888. else
  1889. {
  1890. currentStatus = 0; //OCPP Status: Available
  1891. }
  1892. }
  1893. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1894. {
  1895. currentStatus = 1; //OCPP Status: Preparing
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1898. {
  1899. currentStatus = 2; //OCPP Status: Charging
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1902. {
  1903. currentStatus = 5; //OCPP Status: Finishing
  1904. }
  1905. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1906. {
  1907. currentStatus = 4; //OCPP Status: SuspendedEV
  1908. }
  1909. 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
  1910. {
  1911. currentStatus = 7; //OCPP Status: Unavailable
  1912. }
  1913. 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
  1914. {
  1915. currentStatus = 8; //OCPP Status: Faulted
  1916. }
  1917. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1918. {
  1919. currentStatus = 6; //OCPP Status: Reserved
  1920. }
  1921. }
  1922. }
  1923. else
  1924. {
  1925. for (int index = 0; index < AC_QUANTITY; index++)
  1926. {
  1927. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1928. {
  1929. 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))
  1930. {
  1931. currentStatus = 1; //OCPP Status: Preparing
  1932. }
  1933. else
  1934. {
  1935. currentStatus = 0; //OCPP Status: Available
  1936. }
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1939. {
  1940. currentStatus = 1; //OCPP Status: Preparing
  1941. }
  1942. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1943. {
  1944. currentStatus = 2; //OCPP Status: Charging
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1947. {
  1948. currentStatus = 5; //OCPP Status: Finishing
  1949. }
  1950. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1951. {
  1952. currentStatus = 4; //OCPP Status: SuspendedEV
  1953. }
  1954. 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
  1955. {
  1956. currentStatus = 7; //OCPP Status: Unavailable
  1957. }
  1958. 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
  1959. {
  1960. currentStatus = 8; //OCPP Status: Faulted
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1963. {
  1964. currentStatus = 6; //OCPP Status: Reserved
  1965. }
  1966. }//end of for AC_QUANTITY
  1967. }//END OF ELSE
  1968. //it's option
  1969. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1970. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1971. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1972. random_uuid(guid);
  1973. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1974. , MESSAGE_TYPE_CALL
  1975. , guid
  1976. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1977. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1978. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1979. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1980. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1981. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1982. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1983. LWS_Send(message);
  1984. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1985. 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*/)
  1986. {
  1987. //DEBUG_ERROR("statusNotification mapitem pass");
  1988. result = PASS;
  1989. }
  1990. return result;
  1991. }
  1992. int sendStopTransactionRequest(int gun_index)
  1993. {
  1994. mtrace();
  1995. int result = FAIL;
  1996. //char message[1500]={0};
  1997. char guid[37]={0};
  1998. char tempdata[65]={0};
  1999. //int idx_sample=0;
  2000. DEBUG_ERROR("sendStopTransactionRequest \n");
  2001. memset(queuedata, 0, sizeof(queuedata));
  2002. //ENERGY_ACTIVE_IMPORT_REGISTER
  2003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2004. {
  2005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2006. {
  2007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2008. {
  2009. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2010. }
  2011. }// END OF CHAdeMO_QUANTITY
  2012. for (int index = 0; index < CCS_QUANTITY; index++)
  2013. {
  2014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2015. {
  2016. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2017. }
  2018. }// END OF CCS_QUANTITY
  2019. for (int index = 0; index < GB_QUANTITY; index++)
  2020. {
  2021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2022. {
  2023. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2024. }
  2025. }// END OF GB_QUANTITY
  2026. }
  2027. else
  2028. {
  2029. for (int index = 0; index < AC_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2032. {
  2033. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2034. }
  2035. }// END OF AC_QUANTITY
  2036. }//END OF ELSE
  2037. //Stop Transaction Time
  2038. struct timeval tmnow;
  2039. struct tm *tm;
  2040. char buf[28];//, usec_buf[6];
  2041. gettimeofday(&tmnow, NULL);
  2042. time_t t;
  2043. t = time(NULL);
  2044. /*UTC time and date*/
  2045. tm = gmtime(&t);
  2046. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2048. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2049. random_uuid(guid);
  2050. /***********************************transactionData******************************************************/
  2051. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2053. //=================================
  2054. // Transaction_Begin
  2055. //=================================
  2056. // Energy.Active.Export.Interval
  2057. //idx_sample=0;
  2058. 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
  2059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2061. 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*/]);
  2062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2063. {
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2065. }
  2066. else
  2067. {
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2069. }
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2072. //=================================
  2073. // Transaction_End
  2074. //=================================
  2075. //Current.Export
  2076. //idx_sample=1;
  2077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2078. {
  2079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2080. {
  2081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2082. {
  2083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2084. }
  2085. }
  2086. for (int index = 0; index < CCS_QUANTITY; index++)
  2087. {
  2088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2089. {
  2090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2091. }
  2092. }
  2093. for (int index = 0; index < GB_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2096. {
  2097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2098. }
  2099. }
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2101. }
  2102. else
  2103. {
  2104. for (int index = 0; index < AC_QUANTITY; index++)
  2105. {
  2106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2107. {
  2108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2109. }
  2110. }
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2112. }// END FOR AC ELSE
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2116. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2119. //Energy.Active.Export.Interval
  2120. //idx_sample=2;
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2122. {
  2123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2124. {
  2125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2126. {
  2127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2128. }
  2129. }
  2130. for (int index = 0; index < CCS_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2133. {
  2134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2135. }
  2136. }
  2137. for (int index = 0; index < GB_QUANTITY; index++)
  2138. {
  2139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2140. {
  2141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2142. }
  2143. }
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2145. }
  2146. else
  2147. {
  2148. for (int index = 0; index < AC_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2151. {
  2152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2153. }
  2154. }
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2156. }// END FOR AC ELSE
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2160. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2163. //Power.Active.Export
  2164. //idx_sample=3;
  2165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2166. {
  2167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2170. {
  2171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2172. }
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2177. {
  2178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2179. }
  2180. }
  2181. for (int index = 0; index < GB_QUANTITY; index++)
  2182. {
  2183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2184. {
  2185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2186. }
  2187. }
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2189. }
  2190. else
  2191. {
  2192. for (int index = 0; index < AC_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2195. {
  2196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2197. }
  2198. }
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2200. }// END FOR AC ELSE
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2204. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2207. //Voltage
  2208. //idx_sample=4;
  2209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2210. {
  2211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2214. {
  2215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2216. }
  2217. }
  2218. for (int index = 0; index < CCS_QUANTITY; index++)
  2219. {
  2220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2221. {
  2222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2223. }
  2224. }
  2225. for (int index = 0; index < GB_QUANTITY; index++)
  2226. {
  2227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2228. {
  2229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2230. }
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2233. }
  2234. else
  2235. {
  2236. for (int index = 0; index < AC_QUANTITY; index++)
  2237. {
  2238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2239. {
  2240. 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
  2241. }
  2242. }
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2244. }// END FOR AC ELSE
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2248. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2251. //SoC
  2252. //idx_sample=5;
  2253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2254. {
  2255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2256. {
  2257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2258. {
  2259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2260. }
  2261. }
  2262. for (int index = 0; index < CCS_QUANTITY; index++)
  2263. {
  2264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2265. {
  2266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2267. }
  2268. }
  2269. for (int index = 0; index < GB_QUANTITY; index++)
  2270. {
  2271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2272. {
  2273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2274. }
  2275. }
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2282. } // END FOR DC CASE
  2283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2284. {
  2285. 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\"}]}]}]"
  2286. ,MESSAGE_TYPE_CALL
  2287. ,guid
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2289. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2292. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2293. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2298. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2336. );
  2337. }
  2338. else
  2339. {
  2340. 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\"}]}]}]"
  2341. ,MESSAGE_TYPE_CALL
  2342. ,guid
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2348. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2384. );
  2385. }
  2386. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2387. if(hashmap_operation(0, guid, tempdata) == 1)
  2388. {
  2389. result = PASS;
  2390. DEBUG_INFO("StopTransaction mapitem pass\n");
  2391. }
  2392. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2393. if(GetTransactionQueueNum() == 1)
  2394. {
  2395. LWS_Send(queuedata);
  2396. }
  2397. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2398. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2399. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2400. {
  2401. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2402. }
  2403. #if 0
  2404. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2405. if(hashmap_operation(0, guid, tempdata) == 1)
  2406. {
  2407. result = PASS;
  2408. DEBUG_INFO("StopTransaction mapitem pass\n");
  2409. }
  2410. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2411. #endif
  2412. //for test
  2413. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2414. return result;
  2415. }
  2416. int sendMeterValuesRequest(int gun_index)
  2417. {
  2418. mtrace();
  2419. int result = FAIL;
  2420. // char message[1500]={0};
  2421. char guid[37]={0};
  2422. //int idx_sample=0;
  2423. //int length = 0;
  2424. char tempdata[65]={0};
  2425. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2426. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2427. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2428. {
  2429. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2430. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2431. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2432. return result;
  2433. }
  2434. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2435. {
  2436. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2437. }
  2438. memset(queuedata, 0, sizeof(queuedata));
  2439. //set value
  2440. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2441. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2442. random_uuid(guid);
  2443. //UTC Date time
  2444. struct timeval tmnow;
  2445. struct tm *tm;
  2446. char buf[28];//, usec_buf[6];
  2447. gettimeofday(&tmnow, NULL);
  2448. time_t t;
  2449. t = time(NULL);
  2450. /*UTC time and date*/
  2451. tm = gmtime(&t);
  2452. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2454. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2455. //idx_sample=0;
  2456. //********************************(1)Current.Export************************************************/
  2457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2458. {
  2459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2460. {
  2461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2462. {
  2463. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2464. }
  2465. }
  2466. for (int index = 0; index < CCS_QUANTITY; index++)
  2467. {
  2468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2469. {
  2470. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2471. }
  2472. }
  2473. for (int index = 0; index < GB_QUANTITY; index++)
  2474. {
  2475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2476. {
  2477. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2478. }
  2479. }
  2480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2481. }
  2482. else
  2483. {
  2484. for (int index = 0; index < AC_QUANTITY; index++)
  2485. {
  2486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2487. {
  2488. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2489. }
  2490. }
  2491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2492. }// END FOR AC ELSE
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2496. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2499. //idx_sample=1;
  2500. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2502. {
  2503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2504. {
  2505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2506. {
  2507. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2508. }
  2509. }
  2510. for (int index = 0; index < CCS_QUANTITY; index++)
  2511. {
  2512. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2514. {
  2515. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2517. }
  2518. }
  2519. for (int index = 0; index < GB_QUANTITY; index++)
  2520. {
  2521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2522. {
  2523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2524. }
  2525. }
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2527. }
  2528. else
  2529. {
  2530. for (int index = 0; index < AC_QUANTITY; index++)
  2531. {
  2532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2533. {
  2534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2535. }
  2536. }
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2538. }//END FOR AC ELSE
  2539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2542. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2545. //idx_sample=2;
  2546. //********************************(4)Power.Active.Export************************************************/
  2547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2548. {
  2549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2554. }
  2555. }
  2556. for (int index = 0; index < CCS_QUANTITY; index++)
  2557. {
  2558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2559. {
  2560. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2561. }
  2562. }
  2563. for (int index = 0; index < GB_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2566. {
  2567. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2569. }
  2570. }
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2572. }
  2573. else
  2574. {
  2575. for (int index = 0; index < AC_QUANTITY; index++)
  2576. {
  2577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2578. {
  2579. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2580. }
  2581. }
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2583. }// END FOR AC ELSE
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2587. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2590. //idx_sample=3;
  2591. //***********************************************(5)VOLTAGE******************************************************/
  2592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2593. {
  2594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2595. {
  2596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2597. {
  2598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2599. }
  2600. }
  2601. for (int index = 0; index < CCS_QUANTITY; index++)
  2602. {
  2603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2604. {
  2605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2606. }
  2607. }
  2608. for (int index = 0; index < GB_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2613. }
  2614. }
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2616. }
  2617. else
  2618. {
  2619. for (int index = 0; index < AC_QUANTITY; index++)
  2620. {
  2621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2622. {
  2623. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2624. }
  2625. }
  2626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2627. }//END FOR AC ELSE
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2631. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2635. {
  2636. //idx_sample=4;
  2637. //sampledValue = NULL;
  2638. //***********************************************(6)SOC******************************************************/
  2639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2640. {
  2641. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2642. {
  2643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2644. }
  2645. }
  2646. for (int index = 0; index < CCS_QUANTITY; index++)
  2647. {
  2648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2649. {
  2650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2651. }
  2652. }
  2653. for (int index = 0; index < GB_QUANTITY; index++)
  2654. {
  2655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2656. {
  2657. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2658. }
  2659. }
  2660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2666. }
  2667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2668. {
  2669. 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\"}]}]}]"
  2670. ,MESSAGE_TYPE_CALL
  2671. ,guid
  2672. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2673. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2674. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2710. );
  2711. }
  2712. else
  2713. {
  2714. 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\"}]}]}]"
  2715. ,MESSAGE_TYPE_CALL
  2716. ,guid
  2717. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2718. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2719. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2748. );
  2749. }
  2750. // Put request guid to hash map
  2751. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2752. 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*/)
  2753. {
  2754. result = PASS;
  2755. DEBUG_INFO("MeterValues mapitem pass\n");
  2756. }
  2757. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2758. if(GetTransactionQueueNum() == 1)
  2759. {
  2760. LWS_Send(queuedata);
  2761. }
  2762. #if 0
  2763. // Put request guid to hash map
  2764. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2765. 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*/)
  2766. {
  2767. result = PASS;
  2768. DEBUG_INFO("MeterValues mapitem pass\n");
  2769. }
  2770. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2771. #endif
  2772. return result;
  2773. }
  2774. //==========================================
  2775. // send confirm routine
  2776. //==========================================
  2777. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2778. {
  2779. mtrace();
  2780. int result = FAIL;
  2781. char message[100]={0};
  2782. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2783. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2784. LWS_Send(message);
  2785. result = TRUE;
  2786. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2787. return result;
  2788. }
  2789. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2790. {
  2791. mtrace();
  2792. int result = FAIL;
  2793. char message[100]={0};
  2794. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2795. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2796. LWS_Send(message);
  2797. result = TRUE;
  2798. return result;
  2799. }
  2800. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2801. {
  2802. mtrace();
  2803. int result = FAIL;
  2804. char message[100]={0};
  2805. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2806. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2807. LWS_Send(message);
  2808. result = TRUE;
  2809. return result;
  2810. }
  2811. int sendClearCacheConfirmation(char *uuid,char *payload)
  2812. {
  2813. mtrace();
  2814. int result = FAIL;
  2815. char message[500]={0};
  2816. // int count = 0;
  2817. // int gun_index = 0;
  2818. // char guid[37];
  2819. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2820. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2821. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2822. LWS_Send(message);
  2823. return result;
  2824. }
  2825. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2826. {
  2827. mtrace();
  2828. int result = FAIL;
  2829. char message[500]={0};
  2830. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2831. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2832. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2833. LWS_Send(message);
  2834. return result;
  2835. }
  2836. int sendDataTransferConfirmation(char *uuid,char *payload)
  2837. {
  2838. mtrace();
  2839. char statusStr[20]={0};
  2840. char dataStr[10]={0};
  2841. char sstr[20]={0};
  2842. int c = 0;
  2843. char *loc;
  2844. int result = FAIL;
  2845. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2846. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2847. /**********************status**************************/
  2848. loc = strstr(payload, "status");
  2849. memset(sstr ,0, sizeof(sstr) );
  2850. c = 0;
  2851. while (loc[3+strlen("status")+c] != '\"')
  2852. {
  2853. sstr[c] = loc[3+strlen("status")+c];
  2854. c++;
  2855. }
  2856. sstr[c] = '\0';
  2857. strcpy(statusStr, sstr);
  2858. /**********************data**************************/
  2859. loc = strstr(payload, "data");
  2860. memset(sstr ,0, sizeof(sstr) );
  2861. c = 0;
  2862. while (loc[3+strlen("data")+c] != '\"')
  2863. {
  2864. sstr[c] = loc[3+strlen("data")+c];
  2865. c++;
  2866. }
  2867. sstr[c] = '\0';
  2868. strcpy(dataStr, sstr);
  2869. return result;
  2870. }
  2871. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2872. {
  2873. mtrace();
  2874. int result = FAIL;
  2875. char message[1000]={0};
  2876. double diff_f = 0.0;
  2877. int diff_i = 0;
  2878. int diffSeconds = 0;
  2879. struct tm tp;
  2880. int TimeZero = FALSE;
  2881. int CompositeScheduleIndex = 0;
  2882. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2883. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2884. {
  2885. TimeZero = TRUE;
  2886. }
  2887. else
  2888. {
  2889. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2890. }
  2891. if(TimeZero == FALSE)
  2892. {
  2893. tp.tm_isdst = -1;
  2894. time_t utc = mktime(&tp);
  2895. time_t t = time(NULL);
  2896. diff_f = difftime(t, utc);
  2897. diff_i = (int)diff_f;
  2898. diffSeconds = diff_i % 86400;//86400 seconds/day
  2899. }
  2900. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2901. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2902. #if 0 //remove temporally
  2903. 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}"
  2904. ,MESSAGE_TYPE_CALLRESULT
  2905. ,uuid
  2906. ,payload
  2907. ,connectorIdInt
  2908. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2909. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2910. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2911. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2912. #endif
  2913. if(nPeriod == 0)
  2914. {
  2915. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2916. {
  2917. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2918. ,MESSAGE_TYPE_CALLRESULT
  2919. ,uuid
  2920. ,payload
  2921. ,connectorIdInt);
  2922. }
  2923. else
  2924. {
  2925. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2926. ,MESSAGE_TYPE_CALLRESULT
  2927. ,uuid
  2928. ,payload
  2929. ,connectorIdInt
  2930. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2931. }
  2932. }
  2933. else
  2934. {
  2935. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2936. ,MESSAGE_TYPE_CALLRESULT
  2937. ,uuid
  2938. ,payload
  2939. ,connectorIdInt
  2940. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2941. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2942. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2943. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2944. int len = nPeriod;
  2945. //Last Period StartPriod is less than diffSeconds
  2946. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2947. {
  2948. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2949. , 0
  2950. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2951. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2952. }
  2953. else
  2954. {
  2955. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2956. {
  2957. 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)
  2958. {
  2959. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2960. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2961. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2962. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2963. }
  2964. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2965. {
  2966. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2967. , ((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*/))
  2968. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2969. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2970. }
  2971. }
  2972. }
  2973. sprintf(message + strlen(message), "]}}]");
  2974. }
  2975. LWS_Send(message);
  2976. result = TRUE;
  2977. return result;
  2978. }
  2979. int sendGetConfigurationConfirmation(char *uuid)
  2980. {
  2981. mtrace();
  2982. int result = FAIL;
  2983. int MaxKeySupported = 0;
  2984. int sentConfigurationNumber= 0;
  2985. int sentunConfigurationNumber= 0;
  2986. char message[4000]={0};
  2987. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2988. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2989. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2990. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  2991. ,MESSAGE_TYPE_CALLRESULT
  2992. ,uuid );
  2993. //configuration key
  2994. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2995. {
  2996. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2997. {
  2998. if (sentConfigurationNumber == 0)
  2999. {
  3000. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3001. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3002. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3003. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3004. }
  3005. else
  3006. {
  3007. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3008. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3009. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3010. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3011. }
  3012. sentConfigurationNumber = sentConfigurationNumber + 1;
  3013. }
  3014. }
  3015. sprintf(message + strlen(message), "]");
  3016. if(UnknownKeynum != 0)
  3017. {
  3018. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3019. //unkown key
  3020. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3021. {
  3022. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3023. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3024. if(sentunConfigurationNumber == 0)
  3025. {
  3026. sprintf(message + strlen(message), "\"%s\""
  3027. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3028. }
  3029. else
  3030. {
  3031. sprintf(message + strlen(message), ",\"%s\""
  3032. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3033. }
  3034. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3035. }
  3036. sprintf(message + strlen(message), "]");
  3037. }
  3038. sprintf(message + strlen(message), "}]");
  3039. LWS_Send(message);
  3040. return result;
  3041. }
  3042. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3043. {
  3044. mtrace();
  3045. int result = FAIL;
  3046. char message[400]={0};
  3047. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3048. if(strcmp(payload,"")==0)
  3049. {
  3050. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3051. }
  3052. else
  3053. {
  3054. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3055. }
  3056. LWS_Send(message);
  3057. result = TRUE;
  3058. return result;
  3059. }
  3060. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3061. {
  3062. mtrace();
  3063. int result = FAIL;
  3064. char message[80]={0};
  3065. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3066. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3067. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3068. LWS_Send(message);
  3069. result = TRUE;
  3070. return result;
  3071. }
  3072. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3073. {
  3074. mtrace();
  3075. int result = FAIL;
  3076. char message[80]={0};
  3077. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3078. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3079. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3080. LWS_Send(message);
  3081. result = TRUE;
  3082. return result;
  3083. }
  3084. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3085. {
  3086. mtrace();
  3087. int result = FAIL;
  3088. char message[80]={0};
  3089. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3090. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3091. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3092. LWS_Send(message);
  3093. result = TRUE;
  3094. return result;
  3095. }
  3096. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3097. {
  3098. mtrace();
  3099. int result = FAIL;
  3100. char message[80]={0};
  3101. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3102. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3104. LWS_Send(message);
  3105. result = TRUE;
  3106. return result;
  3107. }
  3108. int sendResetConfirmation(char *uuid,char *payload)
  3109. {
  3110. mtrace();
  3111. int result = FAIL;
  3112. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3113. char message[80]={0};
  3114. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3116. LWS_Send(message);
  3117. result = TRUE;
  3118. return result;
  3119. }
  3120. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3121. {
  3122. mtrace();
  3123. int result = FAIL;
  3124. char message[500]={0};
  3125. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3126. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3127. LWS_Send(message);
  3128. result = TRUE;
  3129. return result;
  3130. }
  3131. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3132. {
  3133. mtrace();
  3134. int result = FAIL;
  3135. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3136. char message[80]={0};
  3137. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3139. LWS_Send(message);
  3140. result = TRUE;
  3141. return result;
  3142. }
  3143. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3144. {
  3145. mtrace();
  3146. int result = FAIL;
  3147. char message[80]={0};
  3148. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3149. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3150. LWS_Send(message);
  3151. result = TRUE;
  3152. return result;
  3153. }
  3154. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3155. {
  3156. mtrace();
  3157. int result = FAIL;
  3158. char message[80]={0};
  3159. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3160. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3161. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3162. LWS_Send(message);
  3163. result = TRUE;
  3164. return result;
  3165. }
  3166. int sendUpdateFirmwareConfirmation(char *uuid)
  3167. {
  3168. mtrace();
  3169. int result = FAIL;
  3170. char message[60]={0};
  3171. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3172. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3173. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3174. LWS_Send(message);
  3175. result = TRUE;
  3176. return result;
  3177. }
  3178. //==========================================
  3179. // send CallError routine
  3180. //==========================================
  3181. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3182. {
  3183. mtrace();
  3184. //int result = FAIL;
  3185. char message[220]={0};
  3186. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3187. #ifdef SystemLogMessage
  3188. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3189. uniqueId, action, errorCode, errorDescription);
  3190. #endif
  3191. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3192. LWS_Send(message);
  3193. //result = TRUE;
  3194. }
  3195. //==========================================
  3196. // Handle server request routine Start
  3197. //==========================================
  3198. #define GUN_NUM 1
  3199. int handleCancelReservationRequest(char *uuid, char *payload)
  3200. {
  3201. mtrace();
  3202. int result = FAIL;
  3203. int gunNO = 0;
  3204. int reservationIdInt =0;
  3205. char comfirmstr[20];
  3206. int c = 0;
  3207. char *loc;
  3208. char sstr[100]={0};
  3209. DEBUG_INFO("handle CancelReservationRequest\n");
  3210. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3211. c = 0;
  3212. loc = strstr(payload, "reservationId");
  3213. memset(sstr ,0, sizeof(sstr) );
  3214. while (loc[strlen("reservationId")+2+c] != '}')
  3215. {
  3216. sstr[c] = loc[strlen("reservationId")+2+c];
  3217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3218. c++;
  3219. }
  3220. sstr[c] = '\0';
  3221. reservationIdInt = atoi(sstr);
  3222. memset(comfirmstr, 0, sizeof comfirmstr);
  3223. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3224. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3225. //check Transaction active
  3226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3227. {
  3228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3229. {
  3230. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3231. {
  3232. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3233. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3234. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3235. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3236. goto end;
  3237. }
  3238. }
  3239. for (int index = 0; index < CCS_QUANTITY; index++)
  3240. {
  3241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3242. {
  3243. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3244. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3245. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3246. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3247. goto end;
  3248. }
  3249. }
  3250. for (int index = 0; index < GB_QUANTITY; index++)
  3251. {
  3252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3253. {
  3254. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3255. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3256. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3257. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3258. goto end;
  3259. }
  3260. }
  3261. }
  3262. else
  3263. {
  3264. for (int index = 0; index < AC_QUANTITY; index++)
  3265. {
  3266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3267. {
  3268. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3269. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3270. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3271. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3272. goto end;
  3273. }
  3274. }
  3275. }// END FOR AC ELSE
  3276. //The reservationId does NOT match the reservationId
  3277. sendCancelReservationConfirmation(uuid, comfirmstr);
  3278. end:
  3279. // Fill in ocpp packet uuid
  3280. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3281. return result;
  3282. }
  3283. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3284. {
  3285. mtrace();
  3286. int result = FAIL;
  3287. int gunIndex = 0;
  3288. int copyTo = 0;
  3289. char sstr[90]={0};
  3290. char typeStr[16]={0};
  3291. char comfirmstr[20];
  3292. int specificId = FALSE;
  3293. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3294. char *loc;
  3295. //int intervalInt = 0;
  3296. int c = 0;
  3297. /*** connectorId ****/
  3298. loc = strstr(payload, "connectorId");
  3299. memset(sstr ,0, sizeof(sstr) );
  3300. c = 0;
  3301. copyTo = 0;
  3302. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3303. {
  3304. if(loc[strlen("connectorId")+2+c] != ' ')
  3305. {
  3306. sstr[copyTo] = loc[strlen("connectorId")+2+c];
  3307. copyTo = copyTo + 1;
  3308. }
  3309. c++;
  3310. }
  3311. sstr[copyTo] = '\0';
  3312. gunIndex = atoi(sstr);
  3313. /***type ****/
  3314. loc = strstr(payload, "type");
  3315. memset(sstr ,0, sizeof(sstr) );
  3316. c = 0;
  3317. copyTo = 0;
  3318. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3319. {
  3320. if(loc[3+strlen("type")+c] != ' ')
  3321. {
  3322. sstr[copyTo] = loc[3+strlen("type")+c];
  3323. copyTo = copyTo + 1;
  3324. }
  3325. c++;
  3326. }
  3327. sstr[copyTo] = '\0';
  3328. strcpy(typeStr, sstr);
  3329. if(gunIndex != 0)
  3330. {
  3331. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3332. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3333. }
  3334. else
  3335. {
  3336. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3337. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3338. }
  3339. memset(comfirmstr, 0, sizeof comfirmstr);
  3340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3341. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3342. {
  3343. specificId = TRUE;
  3344. }
  3345. if(specificId == FALSE)
  3346. goto end;
  3347. if(gunIndex != 0)
  3348. {
  3349. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3350. }
  3351. else
  3352. {
  3353. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3354. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3355. }
  3356. /*
  3357. enum SYSTEM_STATUS
  3358. {
  3359. SYS_MODE_BOOTING = 0,
  3360. SYS_MODE_IDLE = 1,
  3361. SYS_MODE_AUTHORIZING = 2,
  3362. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3363. SYS_MODE_REASSIGN = 4,
  3364. SYS_MODE_PREPARING = 5,
  3365. SYS_MODE_PREPARE_FOR_EV = 6,
  3366. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3367. SYS_MODE_CHARGING = 8,
  3368. SYS_MODE_TERMINATING = 9,
  3369. SYS_MODE_COMPLETE = 10,
  3370. SYS_MODE_ALARM = 11,
  3371. SYS_MODE_FAULT = 12,
  3372. SYS_MODE_RESERVATION = 13,
  3373. SYS_MODE_BOOKING = 14,
  3374. SYS_MODE_MAINTAIN = 15,
  3375. SYS_MODE_DEBUG = 16,
  3376. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3377. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3378. SYS_MODE_UPDATE = 19
  3379. };
  3380. */
  3381. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3382. {
  3383. //check Transaction active
  3384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3385. {
  3386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3387. {
  3388. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3389. {
  3390. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3391. {
  3392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3393. }
  3394. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3395. {
  3396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3397. }
  3398. else
  3399. {
  3400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3401. }
  3402. goto end;
  3403. }
  3404. }//END FOR CHAdeMO_QUANTITY
  3405. for (int index = 0; index < CCS_QUANTITY; index++)
  3406. {
  3407. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3408. {
  3409. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3410. {
  3411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3412. }
  3413. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3414. {
  3415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3416. }
  3417. else
  3418. {
  3419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3420. }
  3421. goto end;
  3422. }
  3423. }//END FOR CCS_QUANTITY
  3424. for (int index = 0; index < GB_QUANTITY; index++)
  3425. {
  3426. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3427. {
  3428. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3429. {
  3430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3431. }
  3432. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3433. {
  3434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3435. }
  3436. else
  3437. {
  3438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3439. }
  3440. goto end;
  3441. }
  3442. }// END FOR GB_QUANTITY
  3443. }
  3444. else
  3445. {
  3446. for (int index = 0; index < AC_QUANTITY; index++)
  3447. {
  3448. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3449. {
  3450. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3451. {
  3452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3453. }
  3454. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3455. {
  3456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3457. }
  3458. else
  3459. {
  3460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3461. }
  3462. goto end;
  3463. }
  3464. }//END FOR AC_QUANTITY
  3465. }// END FOR AC ELSE
  3466. }//END FOR AvailabilityTypeStr[Inoperative]
  3467. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3468. {
  3469. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3470. //check Transaction active
  3471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3472. {
  3473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3474. {
  3475. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3478. goto end;
  3479. }
  3480. }//END FOR CHAdeMO_QUANTITY
  3481. for (int index = 0; index < CCS_QUANTITY; index++)
  3482. {
  3483. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3484. {
  3485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3486. goto end;
  3487. }
  3488. }//END FOR CCS_QUANTITY
  3489. for (int index = 0; index < GB_QUANTITY; index++)
  3490. {
  3491. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3492. {
  3493. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. goto end;
  3496. }
  3497. }// END FOR GB_QUANTITY
  3498. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3499. }
  3500. else
  3501. {
  3502. for (int index = 0; index < AC_QUANTITY; index++)
  3503. {
  3504. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3505. {
  3506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3507. goto end;
  3508. }
  3509. }//END FOR CHAdeMO_QUANTITY
  3510. }//END FOR AC ELSE
  3511. }//END FOR AvailabilityTypeStr[Operative]
  3512. end:
  3513. if(gunIndex != 0)
  3514. {
  3515. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3516. }
  3517. else
  3518. {
  3519. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3520. }
  3521. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3522. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3523. return result;
  3524. }
  3525. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3526. {
  3527. mtrace();
  3528. int result = FAIL;
  3529. char sstr[100]={0};
  3530. char keystr[40]={0};
  3531. char valuestr[100]={0};
  3532. char *loc;
  3533. int c = 0;
  3534. char comfirmstr[20]={0};
  3535. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3536. /***key ****/
  3537. loc = strstr(payload, "key");
  3538. memset(sstr ,0, sizeof(sstr) );
  3539. c = 0;
  3540. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3541. {
  3542. sstr[c] = loc[3+strlen("key")+c];
  3543. c++;
  3544. }
  3545. sstr[c] = '\0';
  3546. strcpy(keystr, sstr);
  3547. //DEBUG_INFO( "keystr=%s\n",keystr);
  3548. /***value ****/
  3549. loc = strstr(payload, "value");
  3550. memset(sstr ,0, sizeof(sstr) );
  3551. c = 0;
  3552. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3553. {
  3554. sstr[c] = loc[3+strlen("value")+c];
  3555. c++;
  3556. }
  3557. sstr[c] = '\0';
  3558. strcpy(valuestr, sstr);
  3559. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3560. if((uuid==NULL) || (payload ==NULL) )
  3561. {
  3562. #ifdef Debug
  3563. DEBUG_INFO("payload is null\n");
  3564. #endif
  3565. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3566. }
  3567. else
  3568. {
  3569. int status = setKeyValue(keystr, valuestr);
  3570. switch(status)
  3571. {
  3572. case ConfigurationStatus_Accepted:
  3573. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3574. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3575. StoreConfigurationTable();
  3576. break;
  3577. case ConfigurationStatus_Rejected:
  3578. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3579. break;
  3580. case RebootRequired:
  3581. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3582. StoreConfigurationTable();
  3583. break;
  3584. case NotSupported:
  3585. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3586. break;
  3587. default:
  3588. break;
  3589. }
  3590. }
  3591. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3592. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3593. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3594. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3595. {
  3596. ChageWebSocketPingInterval(atoi(valuestr));
  3597. }
  3598. return result;
  3599. }
  3600. int handleClearCacheRequest(char *uuid, char *payload)
  3601. {
  3602. mtrace();
  3603. int result = FAIL;
  3604. char comfirmstr[20];
  3605. int fd;
  3606. char rmFileCmd[100]={0};
  3607. struct stat stats;
  3608. DEBUG_INFO("handle ClearCacheRequest\n");
  3609. stat("/Storage/OCPP", &stats);
  3610. // Check for directory existence
  3611. if (S_ISDIR(stats.st_mode) == 1)
  3612. {
  3613. //DEBUG_ERROR("\n OCPP directory exist \n");
  3614. }
  3615. else
  3616. {
  3617. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3618. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3619. system(rmFileCmd);
  3620. }
  3621. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3622. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3623. {
  3624. DEBUG_INFO("AuthorizationCache file exist.\n");
  3625. }
  3626. else
  3627. {
  3628. DEBUG_INFO("AuthorizationCache file not exist\n");
  3629. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3630. if(log == NULL)
  3631. {
  3632. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3633. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3634. goto end;
  3635. }
  3636. else
  3637. {
  3638. fclose(log);
  3639. }
  3640. }
  3641. fd = open(AuthorizationCache_JSON,O_RDWR);
  3642. if(fd < 0)
  3643. {
  3644. DEBUG_INFO("open AuthorizationCache file failed\n");
  3645. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3646. }
  3647. else
  3648. {
  3649. DEBUG_INFO("open AuthorizationCache file successful\n");
  3650. //* 清空? 件 */
  3651. ftruncate(fd,0);
  3652. //* ? 新设置? 件? 移??*/
  3653. lseek(fd,0,SEEK_SET);
  3654. close(fd);
  3655. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3656. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3657. }
  3658. end:
  3659. sendClearCacheConfirmation(uuid, comfirmstr);
  3660. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3661. return result;
  3662. }
  3663. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3664. {
  3665. mtrace();
  3666. int result = FAIL;
  3667. int resultRename;
  3668. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3669. char chargingProfilePurposeStr[26]={0};
  3670. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3671. char tempchargingProfilePurposeStr[26]={0};
  3672. char sstr[160]={0};//sstr[200]={ 0 };
  3673. char str[100]={0};
  3674. int c = 0;
  3675. //int i = 0;
  3676. //char * pch;
  3677. char *loc;
  3678. char fname[200]={0};
  3679. char comfirmstr[20]={0};
  3680. char word[1600]={0};
  3681. int clearflag = FALSE;
  3682. int chargingProfileIdIsNULL = FALSE;
  3683. int connectorIsNULL = FALSE;
  3684. int chargingProfilePurposeIsNULL = FALSE;
  3685. int stackLevelIsNULL = FALSE;
  3686. //int GotoEnd = FALSE;
  3687. FILE *fptr1, *fptr2;
  3688. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3689. int n_chargingProfile=0;
  3690. int isEmptyFile = FALSE;
  3691. char sLineWord[1600]={0};
  3692. char chargingProfiles[10][100]={0};
  3693. int ChargeProfileCount = 0;
  3694. char ch;
  3695. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3696. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3697. //***id ****/
  3698. c = 0;
  3699. loc = strstr(payload, "id");
  3700. memset(sstr ,0, sizeof(sstr) );
  3701. if(loc == NULL)
  3702. {
  3703. chargingProfileIdIsNULL = TRUE;
  3704. }
  3705. else
  3706. {
  3707. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3708. {
  3709. sstr[c] = loc[strlen("id")+2+c];
  3710. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3711. c++;
  3712. }
  3713. sstr[c] = '\0';
  3714. chargingProfileIdInt = atoi(sstr);
  3715. }
  3716. //***connectorId ****/
  3717. c=0;
  3718. loc = strstr(payload, "connectorId");
  3719. memset(sstr ,0, sizeof(sstr) );
  3720. if(loc == NULL)
  3721. {
  3722. connectorIsNULL = TRUE;
  3723. }
  3724. else
  3725. {
  3726. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3727. {
  3728. sstr[c] = loc[strlen("connectorId")+2+c];
  3729. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3730. c++;
  3731. }
  3732. sstr[c] = '\0';
  3733. connectorIdInt = atoi(sstr);
  3734. }
  3735. //***chargingProfilePurpose ****/
  3736. loc = strstr(payload, "chargingProfilePurpose");
  3737. memset(sstr ,0, sizeof(sstr) );
  3738. c = 0;
  3739. if(loc == NULL)
  3740. {
  3741. chargingProfilePurposeIsNULL = TRUE;
  3742. }
  3743. else
  3744. {
  3745. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3746. {
  3747. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3748. c++;
  3749. }
  3750. sstr[c] = '\0';
  3751. strcpy(chargingProfilePurposeStr, sstr);
  3752. }
  3753. //***stackLevel ****/
  3754. c=0;
  3755. loc = strstr(payload, "stackLevel");
  3756. memset(sstr ,0, sizeof(sstr) );
  3757. if(loc == NULL)
  3758. {
  3759. stackLevelIsNULL = TRUE;
  3760. }
  3761. else
  3762. {
  3763. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3764. {
  3765. sstr[c] = loc[strlen("stackLevel")+2+c];
  3766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3767. c++;
  3768. }
  3769. sstr[c] = '\0';
  3770. stackLevelInt = atoi(sstr);
  3771. }
  3772. if(connectorIsNULL == FALSE)
  3773. {
  3774. switch(connectorIdInt)
  3775. {
  3776. case 0:
  3777. if(chargingProfilePurposeIsNULL == TRUE)
  3778. {
  3779. int l = 0;
  3780. strcpy(fname, ChargePointMaxProfile_JSON);
  3781. if((access(fname,F_OK))!=-1)
  3782. {
  3783. strcpy(chargingProfiles[l], fname);
  3784. l = l + 1;
  3785. }
  3786. strcpy(fname, TxDefaultProfile_0_JSON);
  3787. if((access(fname,F_OK))!=-1)
  3788. {
  3789. strcpy(chargingProfiles[l], fname);
  3790. l = l + 1;
  3791. }
  3792. ChargeProfileCount = l;
  3793. }
  3794. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3795. {
  3796. strcpy(fname, ChargePointMaxProfile_JSON);
  3797. if((access(fname,F_OK))!=-1)
  3798. {
  3799. strcpy(chargingProfiles[0], fname);
  3800. ChargeProfileCount = 1;
  3801. }
  3802. }
  3803. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3804. {
  3805. strcpy(fname, TxDefaultProfile_0_JSON);
  3806. if((access(fname,F_OK))!=-1)
  3807. {
  3808. strcpy(chargingProfiles[0], fname);
  3809. ChargeProfileCount = 1;
  3810. }
  3811. }
  3812. break;
  3813. default:
  3814. if(chargingProfilePurposeIsNULL == TRUE)
  3815. {
  3816. int m = 0;
  3817. memset(fname, 0, sizeof fname);
  3818. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3819. if((access(fname,F_OK))!=-1)
  3820. {
  3821. strcpy(chargingProfiles[m], fname);
  3822. m = m + 1;
  3823. }
  3824. memset(fname, 0, sizeof fname);
  3825. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3826. if((access(fname,F_OK))!=-1)
  3827. {
  3828. strcpy(chargingProfiles[m], fname);
  3829. m = m + 1;
  3830. }
  3831. ChargeProfileCount = m;
  3832. }
  3833. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3834. {
  3835. //strcpy(fname, TxDefaultProfile_1_JSON);
  3836. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3837. if((access(fname,F_OK))!=-1)
  3838. {
  3839. strcpy(chargingProfiles[0], fname);
  3840. ChargeProfileCount = 1;
  3841. }
  3842. }
  3843. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3844. {
  3845. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3846. if((access(fname,F_OK))!=-1)
  3847. {
  3848. strcpy(chargingProfiles[0], fname);
  3849. ChargeProfileCount = 1;
  3850. }
  3851. //strcpy(fname, TxProfile_1_JSON);
  3852. }
  3853. //strcpy(fname, ChargePointMaxProfile_JSON );
  3854. break;
  3855. }
  3856. }
  3857. else // Check all Charging Profiles
  3858. {
  3859. int i = 0;
  3860. char fnametemp[200]={0};
  3861. ChargeProfileCount = 0;
  3862. //Check ChargePointMaxProfile.json exit
  3863. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3864. {
  3865. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3866. i = i + 1;
  3867. }
  3868. //Check TxDefaultProfile_0.json exit
  3869. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3870. {
  3871. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3872. i = i + 1;
  3873. }
  3874. //Check TxDefaultProfile_%d.json
  3875. for(int j=1; j <= gunTotalNumber; j++)
  3876. {
  3877. memset(fnametemp, 0, sizeof fnametemp);
  3878. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3879. if((access(fnametemp,F_OK))!=-1)
  3880. {
  3881. strcpy(chargingProfiles[i], fnametemp);
  3882. i = i + 1;
  3883. }
  3884. }
  3885. //Check TxProfile_%d.json
  3886. for(int j=1; j <= gunTotalNumber; j++)
  3887. {
  3888. memset(fnametemp, 0, sizeof fnametemp);
  3889. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3890. if((access(fnametemp,F_OK))!=-1)
  3891. {
  3892. strcpy(chargingProfiles[i], fnametemp);
  3893. i = i + 1;
  3894. }
  3895. }
  3896. ChargeProfileCount = i;
  3897. }// End connectorIsNULL is TRUE
  3898. if(ChargeProfileCount == 0)
  3899. {
  3900. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3901. goto end;
  3902. }
  3903. #if 0
  3904. fptr1 = fopen(fname, "r");
  3905. if (!fptr1)
  3906. {
  3907. //file not exist
  3908. DEBUG_INFO("Unable to open the input file!!\n");
  3909. fptr1 = fopen(fname, "w+");
  3910. }
  3911. fclose(fptr1);
  3912. #endif
  3913. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3914. {
  3915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3916. goto end;
  3917. }
  3918. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3919. {
  3920. memset(str, 0, sizeof str);
  3921. // clear temp file
  3922. sprintf(str,"rm -f %s",temp);
  3923. system(str);
  3924. for(int k=0; k < ChargeProfileCount; k++)
  3925. {
  3926. memset(str, 0, sizeof str);
  3927. //clear file in C
  3928. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3929. system(str);
  3930. }
  3931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3932. goto end;
  3933. }
  3934. else if(connectorIsNULL == TRUE)
  3935. {
  3936. for(int k=0; k < ChargeProfileCount; k++)
  3937. {
  3938. fptr1 = fopen(chargingProfiles[k], "r");
  3939. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3940. //Check Charging Profile Count
  3941. while(fscanf(fptr1, "%s", word) != EOF)
  3942. {
  3943. //DEBUG_INFO("word=%s\n",word);
  3944. if(strstr(word, "chargingProfileId")!= NULL)
  3945. {
  3946. //DEBUG_INFO("test chargingProfileId \n");
  3947. n_chargingProfile = n_chargingProfile + 1;
  3948. //DEBUG_INFO("chargingProfileId Found\n");
  3949. }
  3950. }
  3951. rewind(fptr1);
  3952. //search Charging Profile Element
  3953. //int i= 0;
  3954. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3955. {
  3956. //------------------------tempconnectorIdInt------------------------//
  3957. loc = strstr(sLineWord, "connectorId");
  3958. c = 0;
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[strlen("connectorId")+2+c] != ',')
  3961. {
  3962. sstr[c] = loc[strlen("connectorId")+2+c];
  3963. c++;
  3964. }
  3965. sstr[c] = '\0';
  3966. tempconnectorIdInt = atoi(sstr);
  3967. printf("file's gun number is %d\n", tempconnectorIdInt);
  3968. //--------------------------chargingProfileId--------------------//
  3969. c = 0;
  3970. loc = strstr(sLineWord, "chargingProfileId");
  3971. memset(sstr ,0, sizeof(sstr) );
  3972. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3973. {
  3974. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3976. c++;
  3977. }
  3978. sstr[c] = '\0';
  3979. tempchargingProfileIdInt = atoi(sstr);
  3980. //stackLevel
  3981. c = 0;
  3982. loc = strstr(sLineWord, "stackLevel");
  3983. memset(sstr ,0, sizeof(sstr) );
  3984. while (loc[strlen("stackLevel")+2+c] != ',')
  3985. {
  3986. sstr[c] = loc[strlen("stackLevel")+2+c];
  3987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3988. c++;
  3989. }
  3990. sstr[c] = '\0';
  3991. tempstackLevelInt = atoi(sstr);
  3992. c = 0;
  3993. loc = strstr(sLineWord, "chargingProfilePurpose");
  3994. memset(sstr ,0, sizeof(sstr) );
  3995. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3996. {
  3997. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3998. c++;
  3999. }
  4000. sstr[c] = '\0';
  4001. strcpy(tempchargingProfilePurposeStr, sstr);
  4002. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4003. {
  4004. //------- not write to fptr2-------//
  4005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4006. //clearflag = TRUE;
  4007. }
  4008. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4009. {
  4010. //------- not write to fptr2-------//
  4011. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4012. }
  4013. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4014. {
  4015. //------- not write to fptr2-------//
  4016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4017. }
  4018. else
  4019. {
  4020. fprintf(fptr2, sLineWord);//writing data into file
  4021. }
  4022. memset(sLineWord, 0, sizeof sLineWord);
  4023. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4024. if(clearflag == TRUE)
  4025. {
  4026. fclose(fptr1);
  4027. fclose(fptr2);
  4028. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4029. system(str);
  4030. // clear temp file
  4031. sprintf(str,"rm -f %s",temp);
  4032. system(str);
  4033. }
  4034. else
  4035. {
  4036. fclose(fptr1);
  4037. fclose(fptr2);
  4038. memset(str, 0, sizeof str);
  4039. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4040. system(str);
  4041. resultRename = rename(temp, chargingProfiles[k]);
  4042. if(resultRename == 0)
  4043. {
  4044. DEBUG_INFO("File ChargingProfile renamed successfully");
  4045. }
  4046. else
  4047. {
  4048. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4049. }
  4050. if(comfirmstr[0]== 0)
  4051. {
  4052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4053. }
  4054. //Check chargingProfile is empty file
  4055. /*------ Read the file ----------------*/
  4056. fptr1=fopen(chargingProfiles[k],"r");
  4057. ch=fgetc(fptr1);
  4058. rewind(fptr1);
  4059. memset(sLineWord, 0, sizeof sLineWord);
  4060. if(ch!=EOF)
  4061. {
  4062. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4063. {
  4064. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4065. if(sLineWord[0]=='\0')
  4066. {
  4067. isEmptyFile = TRUE;
  4068. break;
  4069. }
  4070. else
  4071. {
  4072. isEmptyFile = FALSE;
  4073. break;
  4074. }
  4075. }
  4076. }
  4077. fclose(fptr1);
  4078. if(isEmptyFile == TRUE)
  4079. {
  4080. memset(str, 0, sizeof str);
  4081. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4082. system(str);
  4083. }
  4084. }
  4085. }// End of while(int k=0; k < ChargePointCount; k++)
  4086. }
  4087. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4088. {
  4089. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4090. for(int k=0; k < ChargeProfileCount; k++)
  4091. {
  4092. fptr1 = fopen(chargingProfiles[k], "r");
  4093. fptr2 = fopen(temp, "w+");
  4094. //Check Charging Profile Count
  4095. while(fscanf(fptr1, "%s", word) != EOF)
  4096. {
  4097. //DEBUG_INFO("word=%s\n",word);
  4098. if(strstr(word, "chargingProfileId")!= NULL)
  4099. {
  4100. //DEBUG_INFO("test chargingProfileId \n");
  4101. n_chargingProfile = n_chargingProfile + 1;
  4102. //DEBUG_INFO("chargingProfileId Found\n");
  4103. }
  4104. }
  4105. rewind(fptr1);
  4106. //search Charging Profile Element
  4107. //int i= 0;
  4108. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4109. {
  4110. //*************************tempconnectorIdInt*********************************/
  4111. loc = strstr(sLineWord, "connectorId");
  4112. c = 0;
  4113. memset(sstr ,0, sizeof(sstr) );
  4114. while (loc[strlen("connectorId")+2+c] != ',')
  4115. {
  4116. sstr[c] = loc[strlen("connectorId")+2+c];
  4117. c++;
  4118. }
  4119. sstr[c] = '\0';
  4120. tempconnectorIdInt = atoi(sstr);
  4121. //chargingProfileId
  4122. c = 0;
  4123. loc = strstr(sLineWord, "chargingProfileId");
  4124. memset(sstr ,0, sizeof(sstr) );
  4125. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4126. {
  4127. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4129. c++;
  4130. }
  4131. sstr[c] = '\0';
  4132. tempchargingProfileIdInt = atoi(sstr);
  4133. //stackLevel
  4134. c = 0;
  4135. loc = strstr(sLineWord, "stackLevel");
  4136. memset(sstr ,0, sizeof(sstr) );
  4137. while (loc[strlen("stackLevel")+2+c] != ',')
  4138. {
  4139. sstr[c] = loc[strlen("stackLevel")+2+c];
  4140. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4141. c++;
  4142. }
  4143. sstr[c] = '\0';
  4144. tempstackLevelInt = atoi(sstr);
  4145. c = 0;
  4146. loc = strstr(sLineWord, "chargingProfilePurpose");
  4147. memset(sstr ,0, sizeof(sstr) );
  4148. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4149. {
  4150. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4151. c++;
  4152. }
  4153. sstr[c] = '\0';
  4154. strcpy(tempchargingProfilePurposeStr, sstr);
  4155. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4156. {
  4157. //------- not write to fptr2-------//
  4158. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4159. //clearflag = TRUE;
  4160. }
  4161. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4162. {
  4163. //------- not write to fptr2-------//
  4164. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4165. }
  4166. else if(stackLevelIsNULL == TRUE)
  4167. {
  4168. //Clear Whole File
  4169. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4170. clearflag = TRUE;
  4171. break;
  4172. }
  4173. else
  4174. {
  4175. fprintf(fptr2, sLineWord);//writing data into file
  4176. }
  4177. memset(sLineWord, 0, sizeof sLineWord);
  4178. }
  4179. if(clearflag == TRUE)
  4180. {
  4181. fclose(fptr1);
  4182. fclose(fptr2);
  4183. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4184. system(str);
  4185. // clear temp file
  4186. sprintf(str,"rm -f %s",temp);
  4187. system(str);
  4188. }
  4189. else
  4190. {
  4191. fclose(fptr1);
  4192. fclose(fptr2);
  4193. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4194. system(str);
  4195. resultRename = rename(temp, chargingProfiles[k]);
  4196. if(resultRename == 0)
  4197. {
  4198. DEBUG_INFO("File ChargingProfile renamed successfully");
  4199. }
  4200. else
  4201. {
  4202. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4203. }
  4204. if(comfirmstr[0]== 0)
  4205. {
  4206. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4207. }
  4208. //Check chargingProfile is empty file
  4209. /*------ Read the file ----------------*/
  4210. fptr1=fopen(chargingProfiles[k],"r");
  4211. ch=fgetc(fptr1);
  4212. rewind(fptr1);
  4213. memset(sLineWord, 0, sizeof sLineWord);
  4214. if(ch!=EOF)
  4215. {
  4216. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4217. {
  4218. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4219. if(sLineWord[0]=='\0')
  4220. {
  4221. isEmptyFile = TRUE;
  4222. break;
  4223. }
  4224. else
  4225. {
  4226. isEmptyFile = FALSE;
  4227. break;
  4228. }
  4229. }
  4230. }
  4231. fclose(fptr1);
  4232. if(isEmptyFile == TRUE)
  4233. {
  4234. memset(str, 0, sizeof str);
  4235. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4236. system(str);
  4237. }
  4238. /*------- End of reading ---------------*/
  4239. }
  4240. } // while(int k=0; k < ChargeProfileCount; k++)
  4241. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4242. end:
  4243. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4244. return result;
  4245. }
  4246. int handleDataTransferRequest(char *uuid, char *payload)
  4247. {
  4248. mtrace();
  4249. int result = FAIL;
  4250. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4251. char tempvendorId[255]={0};
  4252. char tempmessageId[50]={0};
  4253. char tempdata[50]={0};
  4254. char sstr[160]={0};//sstr[200]={ 0 };
  4255. char message[80]={0};
  4256. int c = 0;
  4257. char *loc;
  4258. DEBUG_INFO("handle DataTransferRequest\n");
  4259. if((uuid != NULL) && (payload != NULL))
  4260. {
  4261. //===============================
  4262. // vendorId
  4263. //===============================
  4264. c = 0;
  4265. loc = strstr(payload, "vendorId");
  4266. while (loc[strlen("vendorId")+3+c] != '\"')
  4267. {
  4268. sstr[c] = loc[strlen("vendorId")+3+c];
  4269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4270. c++;
  4271. }
  4272. sstr[c] = '\0';
  4273. strcpy(tempvendorId,sstr);
  4274. //===============================
  4275. // messageId
  4276. //===============================
  4277. memset(sstr ,0, sizeof(sstr) );
  4278. c = 0;
  4279. loc = strstr(payload, "messageId");
  4280. while (loc[strlen("messageId")+3+c] != '\"')
  4281. {
  4282. sstr[c] = loc[strlen("messageId")+3+c];
  4283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4284. c++;
  4285. }
  4286. sstr[c] = '\0';
  4287. strcpy(tempmessageId,sstr);
  4288. //===============================
  4289. // data
  4290. //===============================
  4291. memset(sstr ,0, sizeof(sstr) );
  4292. c = 0;
  4293. loc = strstr(payload, "data");
  4294. printf("loc=%s\n",loc);
  4295. while (loc[strlen("data")+3+c] != '\"')
  4296. {
  4297. sstr[c] = loc[strlen("data")+3+c];
  4298. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4299. c++;
  4300. }
  4301. sstr[c] = '\0';
  4302. strcpy(tempdata,sstr);
  4303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4304. }
  4305. else
  4306. {
  4307. char guid[37]={0};
  4308. random_uuid(guid);
  4309. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4310. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4311. }
  4312. LWS_Send(message);
  4313. return result;
  4314. }
  4315. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4316. {
  4317. mtrace();
  4318. int result = FAIL;
  4319. int connectorIdInt, durationInt;
  4320. char chargingRateUnitStr[4]={0};
  4321. //int tempconnectorIdInt,
  4322. int tempdurationInt;
  4323. float tempminChargingRateFloat = 0.0;
  4324. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4325. int tempStartPeriodInt=0;
  4326. float tempLimitInt=0.0;//0.1;
  4327. int tempNumberPhasesInt=0;
  4328. char fname[200];
  4329. char comfirmstr[20];
  4330. //float totallimit =0.0;
  4331. float MinChargingRate =0.0;
  4332. //double diff_t;
  4333. //struct tm tp;
  4334. FILE *fptr1;
  4335. int c = 0;
  4336. //int i = 0;
  4337. char * pch;
  4338. char *loc;
  4339. char sstr[200]={ 0 };
  4340. int n_chargingProfile = 0;
  4341. int n_SchedulePeriods = 0;
  4342. char SchedulePeriodList[10][200]={0};
  4343. char sLineWord[1600]={0};
  4344. //int n_periods = 0;
  4345. char word[1000]={0};
  4346. int confirmPeriods = 0;
  4347. struct StructProfile ChargePointMaxProfile;
  4348. struct StructProfile TxDefaultProfile;
  4349. struct StructProfile TxProfile;
  4350. struct StructProfile TxDefaultProfiletemp[2]={0};
  4351. int TxDefaultProfileFileIsNull=FALSE;
  4352. int ChargePointMaxProfileIsNull=FALSE;
  4353. int TxProfileIsNull=FALSE;
  4354. int CompositeSceduleIndex = 0;
  4355. char ChargePointMaxProfileScheduleStr[30]={0};
  4356. char TxDefaultProfileScheduleStr[30]={0};
  4357. char TxProfileScheduleStr[30]={0};
  4358. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4359. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4360. memset(&TxProfile,0,sizeof(struct StructProfile));
  4361. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4362. c=0;
  4363. loc = strstr(payload, "connectorId");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4366. {
  4367. sstr[c] = loc[strlen("connectorId")+2+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. connectorIdInt = atoi(sstr);
  4373. c=0;
  4374. loc = strstr(payload, "duration");
  4375. memset(sstr ,0, sizeof(sstr) );
  4376. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4377. {
  4378. sstr[c] = loc[strlen("duration")+2+c];
  4379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4380. c++;
  4381. }
  4382. sstr[c] = '\0';
  4383. durationInt = atoi(sstr);
  4384. c = 0;
  4385. loc = strstr(payload, "chargingRateUnit");
  4386. memset(sstr ,0, sizeof(sstr) );
  4387. if(loc == NULL)
  4388. {
  4389. }
  4390. else
  4391. {
  4392. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4393. {
  4394. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4395. c++;
  4396. }
  4397. sstr[c] = '\0';
  4398. strcpy(chargingRateUnitStr, sstr);
  4399. }
  4400. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4401. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4402. if(connectorIdInt==0) // connectorId is 0
  4403. {
  4404. //******************************ChargePointMaxProfile*****************************************************/
  4405. strcpy(fname, ChargePointMaxProfile_JSON );
  4406. char word[30]={0};
  4407. char sLineWord[1060]={0};
  4408. int n_chargingProfile=0;
  4409. ChargePointMaxProfileIsNull=TRUE;
  4410. if((access(fname,F_OK))!=-1)
  4411. {
  4412. fptr1 = fopen(fname, "r");
  4413. int c;
  4414. c = fgetc(fptr1);
  4415. //DEBUG_INFO("c:%d\n",c);
  4416. rewind(fptr1);
  4417. if(c == EOF)
  4418. {
  4419. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4420. ChargePointMaxProfileIsNull=TRUE;
  4421. fclose(fptr1);
  4422. }
  4423. else
  4424. {
  4425. ChargePointMaxProfileIsNull=FALSE;
  4426. while(fscanf(fptr1, "%s", word) != EOF)
  4427. {
  4428. if(strcmp(word, "chargingProfileId") == 0)
  4429. {
  4430. n_chargingProfile = n_chargingProfile + 1;
  4431. printf("Found\n");
  4432. }
  4433. }
  4434. rewind(fptr1);
  4435. //search Charging Profile Element
  4436. int i= 0;
  4437. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4438. #if 0
  4439. /***********connectorId****************/
  4440. c = 0;
  4441. loc = strstr(sLineWord, "connectorId");
  4442. // printf("loc=%s\n",loc);
  4443. memset(sstr ,0, sizeof(sstr) );
  4444. while (loc[strlen("connectorId")+2+c] != ',')
  4445. {
  4446. sstr[c] = loc[strlen("connectorId")+2+c];
  4447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4448. c++;
  4449. }
  4450. sstr[c] = '\0';
  4451. tempconnectorIdInt = atoi(sstr);
  4452. #endif
  4453. //***********validFrom**************/
  4454. c = 0;
  4455. loc = strstr(sLineWord, "validFrom");
  4456. //DEBUG_INFO("loc=%s\n",loc);
  4457. memset(sstr ,0, sizeof(sstr) );
  4458. if(loc != NULL)
  4459. {
  4460. while (loc[3+strlen("validFrom")+c] != '\"')
  4461. {
  4462. sstr[c] = loc[3+strlen("validFrom")+c];
  4463. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4464. c++;
  4465. }
  4466. sstr[c] = '\0';
  4467. DEBUG_INFO("validFrom=%s\n",sstr);
  4468. strcpy(tempvalidFromStr,sstr);
  4469. }
  4470. else
  4471. {
  4472. strcpy(tempvalidFromStr,"");
  4473. }
  4474. //**********startSchedule**********/
  4475. c = 0;
  4476. loc = strstr(sLineWord, "startSchedule");
  4477. //DEBUG_INFO("loc=%s\n",loc);
  4478. memset(sstr ,0, sizeof(sstr) );
  4479. while (loc[3+strlen("startSchedule")+c] != '\"')
  4480. {
  4481. sstr[c] = loc[3+strlen("startSchedule")+c];
  4482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. strcpy(tempstartScheduleStr, sstr);
  4487. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4488. //**********chargingRateUnit**********/
  4489. c = 0;
  4490. loc = strstr(sLineWord, "chargingRateUnit");
  4491. memset(sstr ,0, sizeof(sstr) );
  4492. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4493. {
  4494. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4495. c++;
  4496. }
  4497. sstr[c] = '\0';
  4498. strcpy(tempchargingRateUnitStr, sstr);
  4499. //**********minChargingRate*******/
  4500. c = 0;
  4501. loc = strstr(sLineWord, "minChargingRate");
  4502. //printf("loc=%s\n",loc);
  4503. if(loc != NULL)
  4504. {
  4505. memset(sstr ,0, sizeof(sstr) );
  4506. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4507. {
  4508. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4509. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4510. c++;
  4511. }
  4512. sstr[c] = '\0';
  4513. tempminChargingRateFloat = atof(sstr);
  4514. }
  4515. else
  4516. {
  4517. tempminChargingRateFloat = 0.0;
  4518. }
  4519. //
  4520. #if 0
  4521. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4522. tp.tm_isdst = -1;
  4523. time_t utc = mktime(&tp);
  4524. // current time
  4525. time_t t = time(NULL);
  4526. #endif
  4527. //diff_t = difftime(t, utc);
  4528. //parsing strings to words
  4529. i = 0;
  4530. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4531. loc = loc+3+strlen("chargingSchedulePeriod");
  4532. pch = strtok(loc ,"{");
  4533. while (pch != NULL)
  4534. {
  4535. strcpy(SchedulePeriodList[i], pch);
  4536. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4537. //printf ("%s\n",pch);
  4538. pch = strtok (NULL, "{");
  4539. i = i + 1;
  4540. }
  4541. n_SchedulePeriods = i;
  4542. for(int i=0;i<n_SchedulePeriods;i++)
  4543. {
  4544. //*************startPeriod****************/
  4545. c = 0;
  4546. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4547. memset(sstr ,0, sizeof(sstr) );
  4548. while (loc[strlen("startPeriod")+2+c] != ',')
  4549. {
  4550. sstr[c] = loc[strlen("startPeriod")+2+c];
  4551. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4552. c++;
  4553. }
  4554. sstr[c] = '\0';
  4555. tempStartPeriodInt = atoi(sstr);
  4556. //*************limit****************/
  4557. c = 0;
  4558. loc = strstr(SchedulePeriodList[i], "limit");
  4559. memset(sstr ,0, sizeof(sstr) );
  4560. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4561. {
  4562. sstr[c] = loc[strlen("limit")+2+c];
  4563. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4564. c++;
  4565. }
  4566. sstr[c] = '\0';
  4567. tempLimitInt = atof(sstr);
  4568. //*************numberPhases****************/
  4569. c = 0;
  4570. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4571. memset(sstr ,0, sizeof(sstr) );
  4572. if(loc != NULL)
  4573. {
  4574. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4575. {
  4576. sstr[c] = loc[strlen("numberPhases")+2+c];
  4577. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4578. c++;
  4579. }
  4580. sstr[c] = '\0';
  4581. tempNumberPhasesInt = atoi(sstr);
  4582. }
  4583. else
  4584. {
  4585. tempNumberPhasesInt = 0;
  4586. }
  4587. ChargePointMaxProfile.Duration = durationInt;
  4588. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4589. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4590. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4591. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4592. }
  4593. if(MinChargingRate < tempminChargingRateFloat)
  4594. MinChargingRate = tempminChargingRateFloat;
  4595. }
  4596. }// End of file ChargingProfile
  4597. } //THE END OF ACCESS ChargePointMaxProfile
  4598. //******************************TxDefaultProfile***********************************************/
  4599. strcpy(fname, TxDefaultProfile_0_JSON);
  4600. memset(word, 0, 30);
  4601. memset(sLineWord, 0, 1060);
  4602. //char word[30]={0};
  4603. //char sLineWord[1060]={0};
  4604. n_chargingProfile=0;
  4605. TxDefaultProfileFileIsNull=TRUE;
  4606. if((access(fname,F_OK))!=-1)
  4607. {
  4608. fptr1 = fopen(fname, "r");
  4609. c = 0;
  4610. c = fgetc(fptr1);
  4611. //DEBUG_INFO("c:%d\n",c);
  4612. rewind(fptr1);
  4613. if(c == EOF)
  4614. {
  4615. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4616. TxDefaultProfileFileIsNull=TRUE;
  4617. fclose(fptr1);
  4618. }
  4619. else
  4620. {
  4621. TxDefaultProfileFileIsNull=FALSE;
  4622. while(fscanf(fptr1, "%s", word) != EOF)
  4623. {
  4624. if(strcmp(word, "chargingProfileId") == 0)
  4625. {
  4626. n_chargingProfile = n_chargingProfile + 1;
  4627. printf("Found\n");
  4628. }
  4629. }
  4630. rewind(fptr1);
  4631. //search Charging Profile Element
  4632. int i= 0;
  4633. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4634. #if 0
  4635. /***********connectorId****************/
  4636. c = 0;
  4637. loc = strstr(sLineWord, "connectorId");
  4638. // printf("loc=%s\n",loc);
  4639. memset(sstr ,0, sizeof(sstr) );
  4640. while (loc[strlen("connectorId")+2+c] != ',')
  4641. {
  4642. sstr[c] = loc[strlen("connectorId")+2+c];
  4643. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4644. c++;
  4645. }
  4646. sstr[c] = '\0';
  4647. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4648. tempconnectorIdInt = atoi(sstr);
  4649. #endif
  4650. //***********validFrom**************/
  4651. c = 0;
  4652. loc = strstr(sLineWord, "validFrom");
  4653. //DEBUG_INFO("loc=%s\n",loc);
  4654. memset(sstr ,0, sizeof(sstr) );
  4655. if(loc != NULL)
  4656. {
  4657. while (loc[3+strlen("validFrom")+c] != '\"')
  4658. {
  4659. sstr[c] = loc[3+strlen("validFrom")+c];
  4660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4661. c++;
  4662. }
  4663. sstr[c] = '\0';
  4664. DEBUG_INFO("validFrom=%s\n",sstr);
  4665. strcpy(tempvalidFromStr,sstr);
  4666. }
  4667. else
  4668. {
  4669. strcpy(tempvalidFromStr,"");
  4670. }
  4671. //**********startSchedule**********/
  4672. c = 0;
  4673. loc = strstr(sLineWord, "startSchedule");
  4674. //DEBUG_INFO("loc=%s\n",loc);
  4675. memset(sstr ,0, sizeof(sstr) );
  4676. while (loc[3+strlen("startSchedule")+c] != '\"')
  4677. {
  4678. sstr[c] = loc[3+strlen("startSchedule")+c];
  4679. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4680. c++;
  4681. }
  4682. sstr[c] = '\0';
  4683. strcpy(tempstartScheduleStr, sstr);
  4684. strcpy(TxDefaultProfileScheduleStr, sstr);
  4685. //**********chargingRateUnit**********/
  4686. c = 0;
  4687. loc = strstr(sLineWord, "chargingRateUnit");
  4688. memset(sstr ,0, sizeof(sstr) );
  4689. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4690. {
  4691. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4692. c++;
  4693. }
  4694. sstr[c] = '\0';
  4695. strcpy(tempchargingRateUnitStr, sstr);
  4696. //**********minChargingRate*******/
  4697. c = 0;
  4698. loc = strstr(sLineWord, "minChargingRate");
  4699. //printf("loc=%s\n",loc);
  4700. if(loc != NULL)
  4701. {
  4702. memset(sstr ,0, sizeof(sstr) );
  4703. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4704. {
  4705. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4706. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4707. c++;
  4708. }
  4709. sstr[c] = '\0';
  4710. tempminChargingRateFloat = atof(sstr);
  4711. }
  4712. else
  4713. {
  4714. tempminChargingRateFloat = 0.0;
  4715. }
  4716. #if 0
  4717. //
  4718. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4719. tp.tm_isdst = -1;
  4720. time_t utc = mktime(&tp);
  4721. // current time
  4722. time_t t = time(NULL);
  4723. //diff_t = difftime(t, utc);
  4724. #endif
  4725. //parsing strings to words
  4726. i = 0;
  4727. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4728. loc = loc+3+strlen("chargingSchedulePeriod");
  4729. pch = strtok(loc ,"{");
  4730. while (pch != NULL)
  4731. {
  4732. strcpy(SchedulePeriodList[i], pch);
  4733. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4734. //printf ("%s\n",pch);
  4735. pch = strtok (NULL, "{");
  4736. i = i + 1;
  4737. }
  4738. n_SchedulePeriods = i;
  4739. for(int i=0;i<n_SchedulePeriods;i++)
  4740. {
  4741. //*************startPeriod****************/
  4742. c = 0;
  4743. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4744. memset(sstr ,0, sizeof(sstr) );
  4745. while (loc[strlen("startPeriod")+2+c] != ',')
  4746. {
  4747. sstr[c] = loc[strlen("startPeriod")+2+c];
  4748. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4749. c++;
  4750. }
  4751. sstr[c] = '\0';
  4752. tempStartPeriodInt = atoi(sstr);
  4753. //*************limit****************/
  4754. c = 0;
  4755. loc = strstr(SchedulePeriodList[i], "limit");
  4756. memset(sstr ,0, sizeof(sstr) );
  4757. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4758. {
  4759. sstr[c] = loc[strlen("limit")+2+c];
  4760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4761. c++;
  4762. }
  4763. sstr[c] = '\0';
  4764. tempLimitInt = atof(sstr);
  4765. //*************numberPhases****************/
  4766. c = 0;
  4767. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4768. memset(sstr ,0, sizeof(sstr) );
  4769. if(loc != NULL)
  4770. {
  4771. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4772. {
  4773. sstr[c] = loc[strlen("numberPhases")+2+c];
  4774. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4775. c++;
  4776. }
  4777. sstr[c] = '\0';
  4778. tempNumberPhasesInt = atoi(sstr);
  4779. }
  4780. else
  4781. {
  4782. tempNumberPhasesInt = 0;
  4783. }
  4784. TxDefaultProfile.Duration = durationInt;
  4785. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4786. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4787. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4788. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4789. }
  4790. if(MinChargingRate < tempminChargingRateFloat)
  4791. MinChargingRate = tempminChargingRateFloat;
  4792. }
  4793. }
  4794. }// the end of ACCESS TxDefaultProfile
  4795. //--------------------- Composite Schedule-----------------------------//
  4796. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4797. {
  4798. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4799. struct tm tp;
  4800. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4801. tp.tm_isdst = -1;
  4802. time_t utc = mktime(&tp);
  4803. time_t t = time(NULL);
  4804. double diff_f = difftime(t, utc);
  4805. int diff_i; //= (int)diff_f;
  4806. int quotient; //= diff_i / 86400;//86400 seconds/day
  4807. int period = 0;
  4808. if(diff_f >= 0)
  4809. {
  4810. diff_i = (int)diff_f;
  4811. quotient = diff_i / 86400;
  4812. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4813. {
  4814. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4815. {
  4816. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4817. {
  4818. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4819. }
  4820. else
  4821. {
  4822. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4823. }
  4824. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4825. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4826. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4827. period = period + 1;
  4828. }
  4829. }
  4830. }
  4831. confirmPeriods = period;
  4832. }
  4833. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4834. {
  4835. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4836. struct tm tp;
  4837. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4838. tp.tm_isdst = -1;
  4839. time_t utc = mktime(&tp);
  4840. time_t t = time(NULL);
  4841. double diff_f = difftime(t, utc);
  4842. int diff_i; // = (int)diff_f;
  4843. int quotient; // = diff_i / 86400;//86400 seconds/day
  4844. int period = 0;
  4845. if(diff_f >= 0)
  4846. {
  4847. diff_i = (int)diff_f;
  4848. quotient = diff_i / 86400;//86400 seconds/day
  4849. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4850. {
  4851. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4852. {
  4853. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4854. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4855. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4856. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4857. period = period + 1;
  4858. }
  4859. }
  4860. }
  4861. confirmPeriods = period;
  4862. }
  4863. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4864. {
  4865. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4866. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4867. {
  4868. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4869. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4870. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4871. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4872. }
  4873. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4874. }
  4875. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4876. {
  4877. confirmPeriods = 0;
  4878. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4879. goto end;
  4880. }
  4881. //* Define temporary variables */
  4882. struct tm *gtime;
  4883. time_t now;
  4884. char buf[28];
  4885. /* Read the current system time */
  4886. time(&now);
  4887. /* Convert the system time to GMT (now UTC) */
  4888. gtime = gmtime(&now);
  4889. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4890. // make .conf
  4891. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4892. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4893. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4894. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4895. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4896. }
  4897. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4898. {
  4899. //*****************************ChargePointMaxProfile******************************************/
  4900. strcpy(fname, ChargePointMaxProfile_JSON);
  4901. ChargePointMaxProfileIsNull=TRUE;
  4902. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4903. {
  4904. fptr1 = fopen(fname, "r");
  4905. int c;
  4906. c = fgetc(fptr1);
  4907. //DEBUG_INFO("c:%d\n",c);
  4908. rewind(fptr1);
  4909. if(c == EOF)
  4910. {
  4911. DEBUG_INFO("\n End of file reached.");
  4912. ChargePointMaxProfileIsNull=TRUE;
  4913. fclose(fptr1);
  4914. }
  4915. else
  4916. {
  4917. ChargePointMaxProfileIsNull=FALSE;
  4918. while(fscanf(fptr1, "%s", word) != EOF)
  4919. {
  4920. if(strcmp(word, "chargingProfileId") == 0)
  4921. {
  4922. n_chargingProfile = n_chargingProfile + 1;
  4923. }
  4924. }
  4925. rewind(fptr1);
  4926. //search Charging Profile Element
  4927. int i = 0;
  4928. int j = 0;
  4929. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4930. #if 0
  4931. /***********connectorId****************/
  4932. c = 0;
  4933. loc = strstr(sLineWord, "connectorId");
  4934. memset(sstr ,0, sizeof(sstr) );
  4935. while (loc[strlen("connectorId")+2+c] != ',')
  4936. {
  4937. sstr[c] = loc[strlen("connectorId")+2+c];
  4938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4939. c++;
  4940. }
  4941. sstr[c] = '\0';
  4942. tempconnectorIdInt = atoi(sstr);
  4943. #endif
  4944. //***********validFrom**************/
  4945. c = 0;
  4946. loc = strstr(sLineWord, "validFrom");
  4947. if(loc != NULL)
  4948. {
  4949. memset(sstr ,0, sizeof(sstr) );
  4950. while (loc[3+strlen("validFrom")+c] != '\"')
  4951. {
  4952. sstr[c] = loc[3+strlen("validFrom")+c];
  4953. c++;
  4954. }
  4955. sstr[c] = '\0';
  4956. strcpy(tempvalidFromStr,sstr);
  4957. }
  4958. else
  4959. {
  4960. strcpy(tempvalidFromStr,"");
  4961. }
  4962. //***********validFrom**************/
  4963. c = 0;
  4964. loc = strstr(sLineWord, "duration");
  4965. if(loc != NULL)
  4966. {
  4967. memset(sstr ,0, sizeof(sstr) );
  4968. while (loc[2+strlen("duration")+c] != ',')
  4969. {
  4970. sstr[c] = loc[2+strlen("duration")+c];
  4971. c++;
  4972. }
  4973. sstr[c] = '\0';
  4974. tempdurationInt = atoi(sstr);
  4975. }
  4976. else
  4977. {
  4978. tempdurationInt = 0;
  4979. }
  4980. //**********startSchedule**********/
  4981. c = 0;
  4982. loc = strstr(sLineWord, "startSchedule");
  4983. memset(sstr ,0, sizeof(sstr) );
  4984. while (loc[3+strlen("startSchedule")+c] != '\"')
  4985. {
  4986. sstr[c] = loc[3+strlen("startSchedule")+c];
  4987. c++;
  4988. }
  4989. sstr[c] = '\0';
  4990. strcpy(tempstartScheduleStr, sstr);
  4991. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4992. //**********chargingRateUnit**********/
  4993. c = 0;
  4994. loc = strstr(sLineWord, "chargingRateUnit");
  4995. memset(sstr ,0, sizeof(sstr) );
  4996. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4997. {
  4998. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4999. c++;
  5000. }
  5001. sstr[c] = '\0';
  5002. strcpy(tempchargingRateUnitStr, sstr);
  5003. //**********minChargingRate*******/
  5004. c = 0;
  5005. loc = strstr(sLineWord, "minChargingRate");
  5006. if(loc != NULL)
  5007. {
  5008. memset(sstr ,0, sizeof(sstr) );
  5009. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5010. {
  5011. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5012. c++;
  5013. }
  5014. sstr[c] = '\0';
  5015. tempminChargingRateFloat = atof(sstr);
  5016. }
  5017. else
  5018. {
  5019. tempminChargingRateFloat = 0.0;
  5020. }
  5021. #if 0
  5022. //
  5023. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5024. tp.tm_isdst = -1;
  5025. time_t utc = mktime(&tp);
  5026. time_t t = time(NULL);
  5027. //diff_t = difftime(t, utc);
  5028. #endif
  5029. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5030. //DEBUG_INFO(" debug 5 -1\n");
  5031. //parsing strings to words
  5032. i = 0;
  5033. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5034. loc = loc+3+strlen("chargingSchedulePeriod");
  5035. pch = strtok(loc ,"{");
  5036. while (pch != NULL)
  5037. {
  5038. strcpy(SchedulePeriodList[i], pch);
  5039. pch = strtok (NULL, "{");
  5040. i = i + 1;
  5041. }
  5042. n_SchedulePeriods = i;
  5043. for(int i=0;i<n_SchedulePeriods;i++)
  5044. {
  5045. //*************startPeriod****************/
  5046. c = 0;
  5047. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5048. memset(sstr ,0, sizeof(sstr) );
  5049. while (loc[strlen("startPeriod")+2+c] != ',')
  5050. {
  5051. sstr[c] = loc[strlen("startPeriod")+2+c];
  5052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5053. c++;
  5054. }
  5055. sstr[c] = '\0';
  5056. tempStartPeriodInt = atoi(sstr);
  5057. //*************limit****************/
  5058. c = 0;
  5059. loc = strstr(SchedulePeriodList[i], "limit");
  5060. memset(sstr ,0, sizeof(sstr) );
  5061. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5062. {
  5063. sstr[c] = loc[strlen("limit")+2+c];
  5064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5065. c++;
  5066. }
  5067. sstr[c] = '\0';
  5068. tempLimitInt = atof(sstr);
  5069. //*************numberPhases****************/
  5070. c = 0;
  5071. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5072. memset(sstr ,0, sizeof(sstr) );
  5073. if(loc != NULL)
  5074. {
  5075. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5076. {
  5077. sstr[c] = loc[strlen("numberPhases")+2+c];
  5078. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5079. c++;
  5080. }
  5081. sstr[c] = '\0';
  5082. tempNumberPhasesInt = atoi(sstr);
  5083. }
  5084. else
  5085. {
  5086. tempNumberPhasesInt = 0;
  5087. }
  5088. if(j == 0)
  5089. {
  5090. ChargePointMaxProfile.Duration = tempdurationInt;
  5091. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5092. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5093. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5094. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5095. }
  5096. }
  5097. if(MinChargingRate < tempminChargingRateFloat)
  5098. {
  5099. MinChargingRate = tempminChargingRateFloat;
  5100. }
  5101. if(confirmPeriods < n_SchedulePeriods)
  5102. {
  5103. confirmPeriods = n_SchedulePeriods;
  5104. }
  5105. j = j + 1;
  5106. }
  5107. fclose(fptr1);
  5108. }
  5109. }// the end of access file ChargePointMaxProfile
  5110. //****************************TxDefaultProfile************************************************/
  5111. memset(fname, 0, sizeof fname);
  5112. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5113. TxDefaultProfileFileIsNull=TRUE;
  5114. if((access(fname,F_OK))!=-1)
  5115. {
  5116. fptr1 = fopen(fname, "r");
  5117. c = 0;
  5118. c = fgetc(fptr1);
  5119. //DEBUG_INFO("c:%d\n",c);
  5120. rewind(fptr1);
  5121. if(c == EOF)
  5122. {
  5123. DEBUG_INFO("\n End of file reached.");
  5124. TxDefaultProfileFileIsNull=TRUE;
  5125. fclose(fptr1);
  5126. }
  5127. else
  5128. {
  5129. TxDefaultProfileFileIsNull=FALSE;
  5130. while(fscanf(fptr1, "%s", word) != EOF)
  5131. {
  5132. if(strcmp(word, "chargingProfileId") == 0)
  5133. {
  5134. n_chargingProfile = n_chargingProfile + 1;
  5135. }
  5136. }
  5137. rewind(fptr1);
  5138. //search Charging Profile Element
  5139. int i = 0;
  5140. int j = 0;
  5141. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5142. //DEBUG_INFO(" 1-1\n");
  5143. #if 0
  5144. /***********connectorId****************/
  5145. c = 0;
  5146. loc = strstr(sLineWord, "connectorId");
  5147. memset(sstr ,0, sizeof(sstr) );
  5148. while (loc[strlen("connectorId")+2+c] != ',')
  5149. {
  5150. sstr[c] = loc[strlen("connectorId")+2+c];
  5151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5152. c++;
  5153. }
  5154. sstr[c] = '\0';
  5155. tempconnectorIdInt = atoi(sstr);
  5156. #endif
  5157. //***********validFrom**************/
  5158. c = 0;
  5159. loc = strstr(sLineWord, "validFrom");
  5160. if(loc != NULL)
  5161. {
  5162. memset(sstr ,0, sizeof(sstr) );
  5163. while (loc[3+strlen("validFrom")+c] != '\"')
  5164. {
  5165. sstr[c] = loc[3+strlen("validFrom")+c];
  5166. c++;
  5167. }
  5168. sstr[c] = '\0';
  5169. strcpy(tempvalidFromStr,sstr);
  5170. }
  5171. else
  5172. {
  5173. strcpy(tempvalidFromStr,"");
  5174. }
  5175. //***********validFrom**************/
  5176. c = 0;
  5177. loc = strstr(sLineWord, "duration");
  5178. if(loc != NULL)
  5179. {
  5180. memset(sstr ,0, sizeof(sstr) );
  5181. while (loc[2+strlen("duration")+c] != ',')
  5182. {
  5183. sstr[c] = loc[2+strlen("duration")+c];
  5184. c++;
  5185. }
  5186. sstr[c] = '\0';
  5187. tempdurationInt = atoi(sstr);
  5188. }
  5189. else
  5190. {
  5191. tempdurationInt = 0;
  5192. }
  5193. //**********startSchedule**********/
  5194. c = 0;
  5195. loc = strstr(sLineWord, "startSchedule");
  5196. memset(sstr ,0, sizeof(sstr) );
  5197. while (loc[3+strlen("startSchedule")+c] != '\"')
  5198. {
  5199. sstr[c] = loc[3+strlen("startSchedule")+c];
  5200. c++;
  5201. }
  5202. sstr[c] = '\0';
  5203. strcpy(tempstartScheduleStr, sstr);
  5204. strcpy(TxDefaultProfileScheduleStr, sstr);
  5205. //**********chargingRateUnit**********/
  5206. c = 0;
  5207. loc = strstr(sLineWord, "chargingRateUnit");
  5208. memset(sstr ,0, sizeof(sstr) );
  5209. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5210. {
  5211. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5212. c++;
  5213. }
  5214. sstr[c] = '\0';
  5215. strcpy(tempchargingRateUnitStr, sstr);
  5216. //**********minChargingRate*******/
  5217. c = 0;
  5218. loc = strstr(sLineWord, "minChargingRate");
  5219. if(loc != NULL)
  5220. {
  5221. memset(sstr ,0, sizeof(sstr) );
  5222. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5223. {
  5224. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5225. c++;
  5226. }
  5227. sstr[c] = '\0';
  5228. tempminChargingRateFloat = atof(sstr);
  5229. }
  5230. else
  5231. {
  5232. tempminChargingRateFloat = 0.0;
  5233. }
  5234. #if 0
  5235. //
  5236. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5237. tp.tm_isdst = -1;
  5238. time_t utc = mktime(&tp);
  5239. time_t t = time(NULL);
  5240. //diff_t = difftime(t, utc);
  5241. #endif
  5242. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5243. //parsing strings to words
  5244. i = 0;
  5245. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5246. loc = loc+3+strlen("chargingSchedulePeriod");
  5247. pch = strtok(loc ,"{");
  5248. while (pch != NULL)
  5249. {
  5250. strcpy(SchedulePeriodList[i], pch);
  5251. pch = strtok (NULL, "{");
  5252. i = i + 1;
  5253. }
  5254. n_SchedulePeriods = i;
  5255. for(int i=0;i<n_SchedulePeriods;i++)
  5256. {
  5257. //*************startPeriod****************/
  5258. c = 0;
  5259. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5260. memset(sstr ,0, sizeof(sstr) );
  5261. while (loc[strlen("startPeriod")+2+c] != ',')
  5262. {
  5263. sstr[c] = loc[strlen("startPeriod")+2+c];
  5264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5265. c++;
  5266. }
  5267. sstr[c] = '\0';
  5268. tempStartPeriodInt = atoi(sstr);
  5269. //*************limit****************/
  5270. c = 0;
  5271. loc = strstr(SchedulePeriodList[i], "limit");
  5272. memset(sstr ,0, sizeof(sstr) );
  5273. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5274. {
  5275. sstr[c] = loc[strlen("limit")+2+c];
  5276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5277. c++;
  5278. }
  5279. sstr[c] = '\0';
  5280. tempLimitInt = atof(sstr);
  5281. //*************numberPhases****************/
  5282. c = 0;
  5283. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5284. memset(sstr ,0, sizeof(sstr) );
  5285. if(loc != NULL)
  5286. {
  5287. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5288. {
  5289. sstr[c] = loc[strlen("numberPhases")+2+c];
  5290. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5291. c++;
  5292. }
  5293. sstr[c] = '\0';
  5294. tempNumberPhasesInt = atoi(sstr);
  5295. }
  5296. else
  5297. {
  5298. tempNumberPhasesInt = 0;
  5299. }
  5300. if(j == 0)
  5301. {
  5302. TxDefaultProfile.Duration = tempdurationInt;
  5303. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5304. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5305. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5306. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5307. }
  5308. else
  5309. {
  5310. //other stack level charging Profile
  5311. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5312. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5313. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5314. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5315. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5316. }
  5317. }
  5318. if(MinChargingRate < tempminChargingRateFloat)
  5319. MinChargingRate = tempminChargingRateFloat;
  5320. if(confirmPeriods < n_SchedulePeriods)
  5321. confirmPeriods = n_SchedulePeriods;
  5322. j = j + 1;
  5323. //DEBUG_INFO(" 1-2\n");
  5324. }
  5325. fclose(fptr1);
  5326. //Stacking Charging Profiles
  5327. for(int l=0; l <(j-1) ;l++)
  5328. {
  5329. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5330. {
  5331. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5332. {
  5333. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5334. {
  5335. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5336. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5337. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5338. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5339. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5340. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5341. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5342. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5343. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5344. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5345. }
  5346. else
  5347. {
  5348. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5349. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5350. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5351. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5352. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5353. }
  5354. }
  5355. }
  5356. }
  5357. //end of Stacking Charging Profiles
  5358. }
  5359. }// the end of ACCESS TxDefaultProfile
  5360. //****************************TxProfile************************************************/
  5361. memset(fname, 0, sizeof fname);
  5362. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5363. TxProfileIsNull=TRUE;
  5364. if((access(fname,F_OK))!=-1)
  5365. {
  5366. fptr1 = fopen(fname, "r");
  5367. c = 0;
  5368. c = fgetc(fptr1);
  5369. //DEBUG_INFO("c:%d\n",c);
  5370. rewind(fptr1);
  5371. if(c == EOF)
  5372. {
  5373. DEBUG_INFO("\n End of file reached.");
  5374. TxProfileIsNull=TRUE;
  5375. fclose(fptr1);
  5376. }
  5377. else
  5378. {
  5379. TxProfileIsNull=FALSE;
  5380. while(fscanf(fptr1, "%s", word) != EOF)
  5381. {
  5382. if(strcmp(word, "chargingProfileId") == 0)
  5383. {
  5384. n_chargingProfile = n_chargingProfile + 1;
  5385. }
  5386. }
  5387. rewind(fptr1);
  5388. //search Charging Profile Element
  5389. int i= 0;
  5390. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5391. #if 0
  5392. /***********connectorId****************/
  5393. c = 0;
  5394. loc = strstr(sLineWord, "connectorId");
  5395. memset(sstr ,0, sizeof(sstr) );
  5396. while (loc[strlen("connectorId")+2+c] != ',')
  5397. {
  5398. sstr[c] = loc[strlen("connectorId")+2+c];
  5399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5400. c++;
  5401. }
  5402. sstr[c] = '\0';
  5403. tempconnectorIdInt = atoi(sstr);
  5404. #endif
  5405. //***********validFrom**************/
  5406. c = 0;
  5407. loc = strstr(sLineWord, "validFrom");
  5408. if(loc != NULL)
  5409. {
  5410. memset(sstr ,0, sizeof(sstr) );
  5411. while (loc[3+strlen("validFrom")+c] != '\"')
  5412. {
  5413. sstr[c] = loc[3+strlen("validFrom")+c];
  5414. c++;
  5415. }
  5416. sstr[c] = '\0';
  5417. strcpy(tempvalidFromStr,sstr);
  5418. }
  5419. else
  5420. {
  5421. strcpy(tempvalidFromStr,"");
  5422. }
  5423. //**********startSchedule**********/
  5424. c = 0;
  5425. loc = strstr(sLineWord, "startSchedule");
  5426. memset(sstr ,0, sizeof(sstr) );
  5427. while (loc[3+strlen("startSchedule")+c] != '\"')
  5428. {
  5429. sstr[c] = loc[3+strlen("startSchedule")+c];
  5430. c++;
  5431. }
  5432. sstr[c] = '\0';
  5433. strcpy(tempstartScheduleStr, sstr);
  5434. strcpy(TxProfileScheduleStr, sstr);
  5435. //**********chargingRateUnit**********/
  5436. c = 0;
  5437. loc = strstr(sLineWord, "chargingRateUnit");
  5438. memset(sstr ,0, sizeof(sstr) );
  5439. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5440. {
  5441. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5442. c++;
  5443. }
  5444. sstr[c] = '\0';
  5445. strcpy(tempchargingRateUnitStr, sstr);
  5446. //**********minChargingRate*******/
  5447. c = 0;
  5448. loc = strstr(sLineWord, "minChargingRate");
  5449. if(loc != NULL)
  5450. {
  5451. memset(sstr ,0, sizeof(sstr) );
  5452. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5453. {
  5454. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5455. c++;
  5456. }
  5457. sstr[c] = '\0';
  5458. tempminChargingRateFloat = atof(sstr);
  5459. }
  5460. else
  5461. {
  5462. tempminChargingRateFloat = 0.0;
  5463. }
  5464. #if 0
  5465. //
  5466. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5467. tp.tm_isdst = -1;
  5468. time_t utc = mktime(&tp);
  5469. time_t t = time(NULL);
  5470. //diff_t = difftime(t, utc);
  5471. #endif
  5472. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5473. //parsing strings to words
  5474. i = 0;
  5475. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5476. loc = loc+3+strlen("chargingSchedulePeriod");
  5477. pch = strtok(loc ,"{");
  5478. while (pch != NULL)
  5479. {
  5480. strcpy(SchedulePeriodList[i], pch);
  5481. pch = strtok (NULL, "{");
  5482. i = i + 1;
  5483. }
  5484. n_SchedulePeriods = i;
  5485. for(int i=0;i<n_SchedulePeriods;i++)
  5486. {
  5487. //*************startPeriod****************/
  5488. c = 0;
  5489. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5490. memset(sstr ,0, sizeof(sstr) );
  5491. while (loc[strlen("startPeriod")+2+c] != ',')
  5492. {
  5493. sstr[c] = loc[strlen("startPeriod")+2+c];
  5494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5495. c++;
  5496. }
  5497. sstr[c] = '\0';
  5498. tempStartPeriodInt = atoi(sstr);
  5499. //*************limit****************/
  5500. c = 0;
  5501. loc = strstr(SchedulePeriodList[i], "limit");
  5502. memset(sstr ,0, sizeof(sstr) );
  5503. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5504. {
  5505. sstr[c] = loc[strlen("limit")+2+c];
  5506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5507. c++;
  5508. }
  5509. sstr[c] = '\0';
  5510. tempLimitInt = atof(sstr);
  5511. //*************numberPhases****************/
  5512. c = 0;
  5513. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5514. memset(sstr ,0, sizeof(sstr) );
  5515. if(loc != NULL)
  5516. {
  5517. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5518. {
  5519. sstr[c] = loc[strlen("numberPhases")+2+c];
  5520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5521. c++;
  5522. }
  5523. sstr[c] = '\0';
  5524. tempNumberPhasesInt = atoi(sstr);
  5525. }
  5526. else
  5527. {
  5528. tempNumberPhasesInt = 0;
  5529. }
  5530. TxProfile.Duration = durationInt;
  5531. TxProfile.TotalPeriod = n_SchedulePeriods;
  5532. TxProfile.Period[i].Limit = tempLimitInt;
  5533. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5534. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5535. }
  5536. if(MinChargingRate < tempminChargingRateFloat)
  5537. MinChargingRate = tempminChargingRateFloat;
  5538. if(confirmPeriods < n_SchedulePeriods)
  5539. confirmPeriods = n_SchedulePeriods;
  5540. }
  5541. fclose(fptr1);
  5542. }
  5543. }// the end of ACCESS TxProfile
  5544. //CompositeSchedule
  5545. int period=0;
  5546. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5547. {
  5548. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5549. struct tm tp;
  5550. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5551. tp.tm_isdst = -1;
  5552. time_t utc = mktime(&tp);
  5553. time_t t = time(NULL);
  5554. double diff_f = difftime(t, utc);
  5555. int diff_i; // = (int)diff_f;
  5556. int quotient; // = diff_i / 86400;//86400 seconds/day
  5557. //int remainder = diff_i % 86400;
  5558. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5559. {
  5560. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5561. {
  5562. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5563. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5564. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5565. period = period + 1;
  5566. }
  5567. else
  5568. {
  5569. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5570. {
  5571. }
  5572. else
  5573. {
  5574. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5575. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5576. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5577. period = period + 1;
  5578. }
  5579. }
  5580. }
  5581. if( diff_f >= 0)
  5582. {
  5583. diff_i = (int)diff_f;
  5584. quotient = diff_i / 86400;//86400 seconds/day
  5585. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5586. {
  5587. 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))
  5588. {
  5589. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5590. {
  5591. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5592. }
  5593. else
  5594. {
  5595. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5596. }
  5597. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5598. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5599. period = period + 1;
  5600. }
  5601. }
  5602. // Check Last Period
  5603. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5604. {
  5605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5606. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5607. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5608. period = period + 1;
  5609. }
  5610. } // diff_f >= 0
  5611. }
  5612. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5613. {
  5614. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5615. struct tm tp;
  5616. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5617. tp.tm_isdst = -1;
  5618. time_t utc = mktime(&tp);
  5619. time_t t = time(NULL);
  5620. double diff_f = difftime(t, utc);
  5621. int diff_i;// = (int)diff_f;
  5622. int quotient; // = diff_i / 86400;//86400 seconds/day
  5623. //int remainder = diff_i % 86400;
  5624. if(diff_f >= 0)
  5625. {
  5626. diff_i = (int)diff_f;
  5627. quotient = diff_i / 86400;//86400 seconds/day
  5628. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5629. {
  5630. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5631. {
  5632. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5633. {
  5634. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5635. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5636. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5637. period = period + 1;
  5638. }
  5639. else
  5640. {
  5641. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5642. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5643. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5644. period = period + 1;
  5645. }
  5646. }
  5647. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5648. {
  5649. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5650. {
  5651. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5652. {
  5653. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5654. {
  5655. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5656. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5657. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5658. period = period + 1;
  5659. }
  5660. else
  5661. {
  5662. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5663. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5664. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5665. period = period + 1;
  5666. }
  5667. }
  5668. }
  5669. }
  5670. }
  5671. } // end diff_f >= 0
  5672. }
  5673. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5674. {
  5675. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5676. struct tm tp;
  5677. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5678. tp.tm_isdst = -1;
  5679. time_t utc = mktime(&tp);
  5680. time_t t = time(NULL);
  5681. double diff_f = difftime(t, utc);
  5682. int diff_i; // = (int)diff_f;
  5683. int quotient; // = diff_i / 86400;//86400 seconds/day
  5684. //int remainder = diff_i % 86400;
  5685. if(diff_f >= 0)
  5686. {
  5687. diff_i = (int)diff_f;
  5688. quotient = diff_i / 86400;//86400 seconds/day
  5689. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5690. {
  5691. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5692. {
  5693. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5694. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5695. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5696. period = period + 1;
  5697. }
  5698. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5699. {
  5700. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5701. {
  5702. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5703. {
  5704. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5705. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5706. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5707. period = period + 1;
  5708. }
  5709. }
  5710. }
  5711. }
  5712. } // diff_f >= 0
  5713. }
  5714. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5715. {
  5716. confirmPeriods = 0;
  5717. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5718. goto end;
  5719. }
  5720. confirmPeriods = period;
  5721. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5722. //---- Define StartSchedule----/
  5723. struct tm *gtime;
  5724. time_t now;
  5725. char buf[28];
  5726. //---Read the current system time---/
  5727. time(&now);
  5728. //---Convert the system time to GMT (now UTC)---/
  5729. gtime = gmtime(&now);
  5730. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5731. // make .conf
  5732. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5733. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5734. //DEBUG_INFO(" debug 11\n");
  5735. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5736. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5737. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5738. }
  5739. else
  5740. {
  5741. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5742. }
  5743. end:
  5744. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5745. return result;
  5746. }
  5747. int handleGetConfigurationRequest(char *uuid, char *payload)
  5748. {
  5749. mtrace();
  5750. int result = FAIL;
  5751. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5752. //struct json_object *jsonitem;
  5753. int MaxKeySupported = 0;
  5754. int n_keys = 0;
  5755. char requestKey[43][50]={0};
  5756. char search[]="[";
  5757. char sstr[500]={ 0 };
  5758. //int pos;
  5759. int l, c = 0;
  5760. int i = 0;
  5761. char *delim = "\",\"";
  5762. char * pch;
  5763. char *loc = strstr(payload, search);
  5764. //********************* Parsing String ***********************************/
  5765. if(loc == NULL) {
  5766. DEBUG_INFO("no key match in Configuration \n");
  5767. }
  5768. else {
  5769. //pos = loc - payload;
  5770. l = strlen(loc)-4;
  5771. while (c < l)
  5772. {
  5773. sstr[c] = loc[c+2];
  5774. c++;
  5775. }
  5776. sstr[c] = '\0';
  5777. //parsing strings to words
  5778. pch = strtok(sstr,delim);
  5779. if(pch == NULL)
  5780. {
  5781. strcpy(requestKey[0], sstr);
  5782. }
  5783. else
  5784. {
  5785. while (pch != NULL)
  5786. {
  5787. strcpy(requestKey[i], pch);
  5788. pch = strtok (NULL, delim);
  5789. i = i + 1;
  5790. }
  5791. n_keys = i;
  5792. }
  5793. }
  5794. UnknownKeynum = 0;
  5795. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5796. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5797. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5798. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5799. if(n_keys != 0)
  5800. {
  5801. for(int i=0;i<n_keys;i++)
  5802. {
  5803. getKeyValue(requestKey[i]);
  5804. //json_object_put(jsonitem);
  5805. }
  5806. }
  5807. else
  5808. {
  5809. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5810. getKeyValue("");
  5811. }
  5812. processUnkownKey();
  5813. sendGetConfigurationConfirmation(uuid);
  5814. return result;
  5815. }
  5816. static char fnamePlusPath[100]={0};
  5817. static char fnamePWithNoPath[60]={0};
  5818. void checkUploadLog(void)
  5819. {
  5820. FILE *fp;
  5821. /* Open the command for reading. */
  5822. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5823. if (fp == NULL) {
  5824. printf("Failed to run command\n" );
  5825. exit(1);
  5826. }
  5827. int ftppathlen = 0;
  5828. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5829. int i = 0;
  5830. /* Read the output a line at a time - output it. */
  5831. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5832. if(i==0)
  5833. {
  5834. ftppathlen = strlen(fnamePlusPath);
  5835. printf("%s\n", fnamePlusPath);
  5836. fnamePlusPath[ftppathlen]='\0';
  5837. break;
  5838. }
  5839. i= i+1;
  5840. }
  5841. /* close */
  5842. pclose(fp);
  5843. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5844. {
  5845. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5846. {
  5847. fnamePlusPath[k]='\0';
  5848. }
  5849. }
  5850. i=1;
  5851. //char fname[60]={0};
  5852. while(i < ftppathlen)
  5853. {
  5854. int len=ftppathlen-i;
  5855. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5856. {
  5857. printf("compare '/' all right\n");
  5858. break;
  5859. }
  5860. i=i+1;
  5861. }
  5862. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5863. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5864. fnamePWithNoPath[i+1] = '\0';
  5865. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5866. {
  5867. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5868. {
  5869. fnamePWithNoPath[j]='\0';
  5870. }
  5871. }
  5872. FILE* fp1 = fopen(fnamePlusPath, "r");
  5873. if (fp1)
  5874. {
  5875. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5876. // file exists
  5877. fclose(fp1);
  5878. }
  5879. else
  5880. {
  5881. // file doesn't exist
  5882. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5883. }
  5884. }
  5885. static char GetDiagnosticspayloadData[300]={0};
  5886. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5887. {
  5888. mtrace();
  5889. int result = FAIL;
  5890. pthread_t t; // pthread 變數
  5891. system("exec /root/logPackTools 'log' 6");
  5892. #if 0
  5893. //char buffer [128];
  5894. time (&rawtime);
  5895. //printf("%ld\n", rawtime);
  5896. timeinfo = localtime (&rawtime);
  5897. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5898. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5899. if((access(fnamePlusPath,F_OK))!=-1)
  5900. {
  5901. DEBUG_INFO("fnamePlusPath exist.\n");
  5902. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5903. }
  5904. else
  5905. {
  5906. DEBUG_INFO("fnamePlusPath not exist!\n");
  5907. }
  5908. #endif
  5909. checkUploadLog();
  5910. memset(GetDiagnosticspayloadData, 0, 300);
  5911. strcpy(GetDiagnosticspayloadData, payload);
  5912. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5913. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5914. return result;
  5915. }
  5916. void* GetDiagnosticsProcess(void* data)
  5917. {
  5918. pthread_detach(pthread_self());
  5919. mtrace();
  5920. int retriesInt=0, retryIntervalInt=0;
  5921. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5922. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5923. 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};
  5924. int port=0;
  5925. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5926. int c = 0;
  5927. char *loc;
  5928. int isSuccess = FALSE;
  5929. char ftpbuf[200]={0};
  5930. //char temp[100]={0};
  5931. char * pch;
  5932. // [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"}]
  5933. char str[300]={ 0 };
  5934. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5935. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5936. DEBUG_INFO("GetDiagnosticsProcess\n");
  5937. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5938. //****************location*******************/
  5939. c = 0;
  5940. memset(sstr ,0, sizeof(sstr) );
  5941. loc = strstr(str, "location");
  5942. while (loc[3+strlen("location")+c] != '\"')
  5943. {
  5944. sstr[c] = loc[3+strlen("location")+c];
  5945. c++;
  5946. }
  5947. sstr[c] = '\0';
  5948. strcpy(locationstr,sstr);
  5949. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5950. if(strcmp(locationstr,"")==0)
  5951. {
  5952. DEBUG_INFO("location is <Empty>!\n");
  5953. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5954. goto end;
  5955. }
  5956. //****************retries*******************/
  5957. c = 0;
  5958. loc = strstr(str, "retries");
  5959. if(loc == NULL)
  5960. {
  5961. retriesIsNULL = TRUE;
  5962. }
  5963. else
  5964. {
  5965. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5966. {
  5967. sstr[c] = loc[strlen("retries")+2+c];
  5968. c++;
  5969. }
  5970. sstr[c] = '\0';
  5971. retriesInt = atoi(sstr);
  5972. }
  5973. if(retriesIsNULL == TRUE)
  5974. {
  5975. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5976. }
  5977. //****************retryInterval*******************/
  5978. c = 0;
  5979. loc = strstr(str, "retryInterval");
  5980. if(loc == NULL)
  5981. {
  5982. retryIntervalIsNULL = TRUE;
  5983. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5984. }
  5985. else
  5986. {
  5987. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5988. {
  5989. sstr[c] = loc[strlen("retryInterval")+2+c];
  5990. c++;
  5991. }
  5992. sstr[c] = '\0';
  5993. retryIntervalInt = atoi(sstr);
  5994. }
  5995. //****************startTime*******************/
  5996. c = 0;
  5997. memset(sstr ,0, sizeof(sstr) );
  5998. loc = strstr(str, "startTime");
  5999. if(loc == NULL)
  6000. {
  6001. startTimeIsNULL = TRUE;
  6002. }
  6003. else
  6004. {
  6005. while (loc[3+strlen("startTime")+c] != '\"')
  6006. {
  6007. sstr[c] = loc[3+strlen("startTime")+c];
  6008. c++;
  6009. }
  6010. sstr[c] = '\0';
  6011. strcpy(startTimestr,sstr);
  6012. }
  6013. //****************stopTime*******************/
  6014. c = 0;
  6015. memset(sstr ,0, sizeof(sstr) );
  6016. loc = strstr(str, "stopTime");
  6017. if(loc == NULL)
  6018. {
  6019. stopTimeIsNULL = TRUE;
  6020. }
  6021. else
  6022. {
  6023. while (loc[3+strlen("stopTime")+c] != '\"')
  6024. {
  6025. sstr[c] = loc[3+strlen("stopTime")+c];
  6026. c++;
  6027. }
  6028. sstr[c] = '\0';
  6029. strcpy(stopTimestr,sstr);
  6030. }
  6031. memset(protocol, 0, sizeof(protocol));
  6032. memset(user, 0, sizeof(user) );
  6033. memset(password, 0, sizeof(password));
  6034. memset(host, 0, sizeof(host));
  6035. memset(path, 0, sizeof(path));
  6036. memset(ftppath, 0, sizeof(ftppath));
  6037. memset(host1, 0, sizeof(host1));
  6038. memset(path1, 0, sizeof(path1));
  6039. /*location: ftp://user:password@host:port/path*/
  6040. #if 0
  6041. time_t rawtime;
  6042. struct tm * timeinfo;
  6043. //char buffer [128];
  6044. time (&rawtime);
  6045. //printf("%ld\n", rawtime);
  6046. timeinfo = localtime (&rawtime);
  6047. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6048. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6049. #endif
  6050. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6051. if((access(fnamePlusPath,F_OK))!=-1)
  6052. {
  6053. DEBUG_INFO("fnamePlusPath exist.\n");
  6054. }
  6055. else
  6056. {
  6057. DEBUG_INFO("fnamePlusPath not exist!\n");
  6058. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6059. goto end;
  6060. }
  6061. pch=strchr(locationstr,'@');
  6062. if(pch==NULL)
  6063. {
  6064. sscanf(locationstr,
  6065. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6066. protocol, host, &port, path);
  6067. strcpy(user,"anonymous");
  6068. strcpy(password,"");
  6069. }
  6070. else
  6071. {
  6072. //DEBUG_INFO("pch=%s\n", pch);
  6073. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6074. protocol, user, password, host, &port, path);
  6075. }
  6076. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6077. {
  6078. DEBUG_INFO("protocol is not ftp/http ! \n");
  6079. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6080. goto end;
  6081. }
  6082. if(strncmp(locationstr,"http", 4) == 0)
  6083. {
  6084. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6085. sprintf(ftppath,"/%s", path);
  6086. do{
  6087. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6088. sleep(retryIntervalInt);
  6089. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6090. if(!isSuccess)
  6091. {
  6092. DEBUG_INFO("Diagnostics fail.\n");
  6093. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6094. }
  6095. else
  6096. {
  6097. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6098. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6099. }
  6100. }
  6101. else
  6102. {
  6103. sscanf(host,"%[^/]%s",host1, path1);
  6104. sprintf(ftppath,"%s", path1);
  6105. int ftppathlen=strlen(ftppath);
  6106. int i=1;
  6107. char filenametemp[50];
  6108. while(i < ftppathlen)
  6109. {
  6110. int len=ftppathlen-i;
  6111. if(ftppath[len]== 47) // '/' ascll code: 47
  6112. {
  6113. DEBUG_INFO("find '/' all right\n");
  6114. break;
  6115. }
  6116. i=i+1;
  6117. }
  6118. memset(filenametemp, 0, sizeof(filenametemp));
  6119. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6120. filenametemp[i+1] = 0;
  6121. memset(ftpbuf, 0, sizeof(ftpbuf));
  6122. if(port == 0)
  6123. port = 21;
  6124. do{
  6125. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6126. sleep(retryIntervalInt);
  6127. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6128. if(!isSuccess)
  6129. {
  6130. DEBUG_INFO("Diagnostics fail.\n");
  6131. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6132. }
  6133. else
  6134. {
  6135. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6136. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6137. }
  6138. }
  6139. end:
  6140. DiagnosticsStatusNotificationStatus = 0; //Idle
  6141. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6142. }
  6143. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6144. {
  6145. mtrace();
  6146. int result = FAIL;
  6147. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6148. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6149. {
  6150. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6151. localversion = -1;
  6152. }
  6153. else
  6154. {
  6155. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6156. OCPP_getListVerion();
  6157. }
  6158. //from db.OCPP_getListVerion
  6159. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6160. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6161. sendGetLocalListVersionConfirmation(uuid,"");
  6162. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6163. return result;
  6164. }
  6165. int handleRemoteStartRequest(char *uuid, char *payload)
  6166. {
  6167. mtrace();
  6168. int result = FAIL;
  6169. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6170. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6171. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6172. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6173. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6174. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6175. int chargingSchedulePeriodCount = 0;
  6176. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6177. int c = 0;
  6178. char *loc;
  6179. char comfirmstr[20]={0};
  6180. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6181. if(server_pending == TRUE)
  6182. {
  6183. return 0;
  6184. }
  6185. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6186. //**********connectorId****************/
  6187. c = 0;
  6188. memset(sstr ,0, sizeof(sstr) );
  6189. loc = strstr(payload, "connectorId");
  6190. if(loc == NULL)
  6191. {
  6192. connectorIdIsNULL = TRUE;
  6193. }
  6194. else
  6195. {
  6196. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6197. {
  6198. sstr[c] = loc[strlen("connectorId")+2+c];
  6199. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6200. c++;
  6201. }
  6202. sstr[c] = '\0';
  6203. connectorIdInt = atoi(sstr);
  6204. }
  6205. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6206. {
  6207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6208. goto end;
  6209. }
  6210. //****************idTag*******************/
  6211. c = 0;
  6212. memset(sstr ,0, sizeof(sstr) );
  6213. loc = strstr(payload, "idTag");
  6214. while (loc[3+strlen("idTag")+c] != '\"')
  6215. {
  6216. sstr[c] = loc[3+strlen("idTag")+c];
  6217. c++;
  6218. }
  6219. sstr[c] = '\0';
  6220. strcpy(idTagstr,sstr);
  6221. //****************chargingProfile*******************/
  6222. c = 0;
  6223. memset(sstr ,0, sizeof(sstr) );
  6224. loc = strstr(payload, "chargingProfile");
  6225. if(loc == NULL)
  6226. {
  6227. chargingProfileIsNULL = TRUE;
  6228. }
  6229. else
  6230. {
  6231. //****************chargingProfileId*******************/
  6232. c=0;
  6233. loc = strstr(payload, "chargingProfileId");
  6234. memset(sstr ,0, sizeof(sstr) );
  6235. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6236. {
  6237. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6238. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6239. c++;
  6240. }
  6241. sstr[c] = '\0';
  6242. chargingProfileIdInt = atoi(sstr);
  6243. //****************transactionId*******************/
  6244. loc = strstr(payload, "transactionId");
  6245. if(loc == NULL)
  6246. {
  6247. transactionIdIsNULL = TRUE;
  6248. }
  6249. else
  6250. {
  6251. c=0;
  6252. memset(sstr ,0, sizeof(sstr) );
  6253. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6254. {
  6255. sstr[c] = loc[strlen("transactionId")+2+c];
  6256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6257. c++;
  6258. }
  6259. sstr[c] = '\0';
  6260. transactionIdInt = atoi(sstr);
  6261. }
  6262. //****************stackLevel*******************/
  6263. c=0;
  6264. loc = strstr(payload, "stackLevel");
  6265. memset(sstr ,0, sizeof(sstr) );
  6266. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6267. {
  6268. sstr[c] = loc[strlen("stackLevel")+2+c];
  6269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6270. c++;
  6271. }
  6272. sstr[c] = '\0';
  6273. stackLevelInt = atoi(sstr);
  6274. //****************chargingProfilePurpose*******************/
  6275. c = 0;
  6276. memset(sstr ,0, sizeof(sstr) );
  6277. loc = strstr(payload, "chargingProfilePurpose");
  6278. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6279. {
  6280. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6281. c++;
  6282. }
  6283. sstr[c] = '\0';
  6284. strcpy(chargingProfilePurposestr,sstr);
  6285. //****************chargingProfileKind*******************/
  6286. c = 0;
  6287. memset(sstr ,0, sizeof(sstr) );
  6288. loc = strstr(payload, "chargingProfileKind");
  6289. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6290. {
  6291. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6292. c++;
  6293. }
  6294. sstr[c] = '\0';
  6295. strcpy(chargingProfileKindstr,sstr);
  6296. //****************recurrencyKind*******************/
  6297. loc = strstr(payload, "recurrencyKind");
  6298. if(loc == NULL)
  6299. {
  6300. recurrencyKindIsNULL = TRUE;
  6301. }
  6302. else
  6303. {
  6304. c = 0;
  6305. memset(sstr ,0, sizeof(sstr) );
  6306. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6307. {
  6308. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6309. c++;
  6310. }
  6311. sstr[c] = '\0';
  6312. strcpy(recurrencyKindstr,sstr);
  6313. }
  6314. //****************validFrom*******************/
  6315. loc = strstr(payload, "validFrom");
  6316. if(loc == NULL)
  6317. {
  6318. validFromIsNULL = TRUE;
  6319. }
  6320. else
  6321. {
  6322. c = 0;
  6323. memset(sstr ,0, sizeof(sstr) );
  6324. while (loc[3+strlen("validFrom")+c] != '\"')
  6325. {
  6326. sstr[c] = loc[3+strlen("validFrom")+c];
  6327. c++;
  6328. }
  6329. sstr[c] = '\0';
  6330. strcpy(validFromstr,sstr);
  6331. }
  6332. //****************validTo*******************/
  6333. loc = strstr(payload, "validTo");
  6334. if(loc == NULL)
  6335. {
  6336. validToIsNULL = TRUE;
  6337. }
  6338. else
  6339. {
  6340. c = 0;
  6341. memset(sstr ,0, sizeof(sstr) );
  6342. while (loc[3+strlen("validTo")+c] != '\"')
  6343. {
  6344. sstr[c] = loc[3+strlen("validTo")+c];
  6345. c++;
  6346. }
  6347. sstr[c] = '\0';
  6348. strcpy(validTostr,sstr);
  6349. }
  6350. //****************chargingSchedule*******************/
  6351. loc = strstr(payload, "chargingSchedule");
  6352. if(loc != NULL)
  6353. {
  6354. //****************duration*******************/
  6355. loc = strstr(payload, "duration");
  6356. if(loc == NULL)
  6357. {
  6358. durationIsNULL = TRUE;
  6359. }
  6360. else
  6361. {
  6362. c=0;
  6363. memset(sstr ,0, sizeof(sstr) );
  6364. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6365. {
  6366. sstr[c] = loc[strlen("duration")+2+c];
  6367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6368. c++;
  6369. }
  6370. sstr[c] = '\0';
  6371. durationInt = atoi(sstr);
  6372. }
  6373. //****************startSchedule******************/
  6374. loc = strstr(payload, "startSchedule");
  6375. if(loc == NULL)
  6376. {
  6377. startScheduleIsNULL = TRUE;
  6378. }
  6379. else
  6380. {
  6381. c = 0;
  6382. memset(sstr ,0, sizeof(sstr) );
  6383. while (loc[3+strlen("startSchedule")+c] != '\"')
  6384. {
  6385. sstr[c] = loc[3+strlen("startSchedule")+c];
  6386. c++;
  6387. }
  6388. sstr[c] = '\0';
  6389. strcpy(startSchedulestr,sstr);
  6390. }
  6391. //****************chargingRateUnit*******************/
  6392. c = 0;
  6393. memset(sstr ,0, sizeof(sstr) );
  6394. loc = strstr(payload, "chargingRateUnit");
  6395. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6396. {
  6397. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6398. c++;
  6399. }
  6400. sstr[c] = '\0';
  6401. strcpy(chargingRateUnitstr,sstr);
  6402. //****************minChargingRate*******************/
  6403. loc = strstr(payload, "minChargingRate");
  6404. if(loc == NULL)
  6405. {
  6406. minChargingRateIsNULL = TRUE;
  6407. }
  6408. else
  6409. {
  6410. c=0;
  6411. memset(sstr ,0, sizeof(sstr) );
  6412. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6413. {
  6414. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6416. c++;
  6417. }
  6418. sstr[c] = '\0';
  6419. minChargingRateflaot = atof(sstr);
  6420. }
  6421. //****************chargingSchedulePeriod count*******************/
  6422. int what_len = strlen("startPeriod");
  6423. char *where = payload;
  6424. while ((where = strstr(where, "startPeriod"))) {
  6425. where += what_len;
  6426. chargingSchedulePeriodCount++;
  6427. }
  6428. where = payload;
  6429. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6430. {
  6431. //****************startPeriod*******************/
  6432. c=0;
  6433. loc = strstr(where, "startPeriod");
  6434. memset(sstr ,0, sizeof(sstr) );
  6435. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6436. {
  6437. sstr[c] = loc[strlen("startPeriod")+2+c];
  6438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6439. c++;
  6440. }
  6441. sstr[c] = '\0';
  6442. startPeriodInt[periodNums] = atoi(sstr);
  6443. //****************limit*******************/
  6444. c=0;
  6445. loc = strstr(where, "limit");
  6446. memset(sstr ,0, sizeof(sstr) );
  6447. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6448. {
  6449. sstr[c] = loc[strlen("limit")+2+c];
  6450. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6451. c++;
  6452. }
  6453. sstr[c] = '\0';
  6454. limitflaot[periodNums] = atof(sstr);
  6455. //****************numberPhases*******************/
  6456. loc = strstr(where, "numberPhases");
  6457. if(loc == NULL)
  6458. {
  6459. numberPhasesIsNULL = TRUE;
  6460. }
  6461. else
  6462. {
  6463. c=0;
  6464. memset(sstr ,0, sizeof(sstr) );
  6465. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6466. {
  6467. sstr[c] = loc[strlen("numberPhases")+2+c];
  6468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6469. c++;
  6470. }
  6471. sstr[c] = '\0';
  6472. numberPhasesInt[periodNums] = atoi(sstr);
  6473. }
  6474. where = loc;
  6475. }
  6476. }
  6477. }
  6478. /*
  6479. enum _SYSTEM_STATUS
  6480. {
  6481. S_BOOTING = 0,
  6482. S_IDLE, = 1
  6483. S_AUTHORIZING, =2
  6484. S_REASSIGN_CHECK, =3
  6485. S_REASSIGN, =4
  6486. S_PRECHARGE, =5
  6487. S_PREPARING_FOR_EV, =6
  6488. S_PREPARING_FOR_EVSE, =7
  6489. S_CHARGING, =8
  6490. S_TERMINATING, =9
  6491. S_COMPLETE, =10
  6492. S_ALARM, =11
  6493. S_FAULT =12
  6494. }
  6495. */
  6496. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6497. {
  6498. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6499. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6500. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6501. //check Transaction active
  6502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6503. {
  6504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6507. {
  6508. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6509. {
  6510. //Reserved
  6511. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6512. }
  6513. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6514. {
  6515. //Reserved
  6516. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6518. goto end;
  6519. }
  6520. else
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6523. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6524. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6525. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6526. {
  6527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6528. goto end;
  6529. }
  6530. }//END FOR ELSE
  6531. }
  6532. }// END FOR CHAdeMO_QUANTITY
  6533. for (int index = 0; index < CCS_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6536. {
  6537. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6538. {
  6539. //Reserved
  6540. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6541. }
  6542. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6543. {
  6544. //Reserved
  6545. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6547. goto end;
  6548. }
  6549. else
  6550. {
  6551. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6552. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6553. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6554. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6555. {
  6556. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6557. goto end;
  6558. }
  6559. }// END FOR ELSE
  6560. }
  6561. }// END FOR CCS_QUANTITY
  6562. for (int index = 0; index < GB_QUANTITY; index++)
  6563. {
  6564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6565. {
  6566. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6567. {
  6568. //Reserved
  6569. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6570. }
  6571. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6572. {
  6573. //Reserved
  6574. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6576. goto end;
  6577. }
  6578. else
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6581. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6582. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6583. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6584. {
  6585. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6586. goto end;
  6587. }
  6588. }// END FOR ELSE
  6589. }
  6590. } // END FOR GB_QUANTITY
  6591. }
  6592. else
  6593. {
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6597. {
  6598. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[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.AcChargingData[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.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6613. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6614. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6615. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[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 AC_QUANTITY
  6623. }
  6624. if(chargingProfileIsNULL == FALSE)
  6625. {
  6626. //ChargingProfile
  6627. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6628. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6629. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6630. if(recurrencyKindIsNULL == FALSE) //OPTION
  6631. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6632. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6633. if(transactionIdIsNULL == FALSE) // OPTION
  6634. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6635. if(validFromIsNULL == FALSE) // OPTION
  6636. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6637. if(validToIsNULL == FALSE) //OPTION
  6638. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6639. //ChargingSchedule
  6640. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6641. if(durationIsNULL == FALSE) //OPTION
  6642. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6643. if(minChargingRateIsNULL == FALSE) //OPTION
  6644. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6645. if(startScheduleIsNULL == FALSE) //OPTION
  6646. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6647. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6648. {
  6649. //ChargingSchedulePeriod
  6650. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6651. if(numberPhasesIsNULL == FALSE)
  6652. {
  6653. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6654. }
  6655. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6656. }
  6657. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6658. {
  6659. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6660. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6661. //memset idTag
  6662. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6663. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6664. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6665. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6666. }
  6667. else
  6668. {
  6669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6670. }
  6671. }
  6672. else
  6673. {
  6674. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6675. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6676. //memset idTag
  6677. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6678. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6679. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6680. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6681. }
  6682. }
  6683. else
  6684. {
  6685. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6686. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6687. }
  6688. end:
  6689. if(connectorIdIsNULL == FALSE)
  6690. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6691. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6692. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6693. //OCPP send RemoteStartConfirmation by first.
  6694. sendRemoteStartConfirmation(uuid, comfirmstr);
  6695. return result;
  6696. }
  6697. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6698. {
  6699. mtrace();
  6700. int result = FAIL;
  6701. int match = FALSE;
  6702. int GunNO = 0;
  6703. int transactionIdInt=0;
  6704. int transactionIdIsNULL= FALSE;
  6705. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6706. int c = 0;
  6707. char *loc;
  6708. char comfirmstr[20];
  6709. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6710. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6711. if(server_pending == TRUE)
  6712. {
  6713. return 0;
  6714. }
  6715. c=0;
  6716. loc = strstr(payload, "transactionId");
  6717. if(loc == NULL)
  6718. {
  6719. transactionIdIsNULL= TRUE;
  6720. }
  6721. else
  6722. {
  6723. memset(sstr ,0, sizeof(sstr) );
  6724. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6725. {
  6726. sstr[c] = loc[strlen("transactionId")+2+c];
  6727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6728. c++;
  6729. }
  6730. sstr[c] = '\0';
  6731. transactionIdInt = atoi(sstr);
  6732. }
  6733. if(transactionIdIsNULL == FALSE)
  6734. {
  6735. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6736. {
  6737. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6738. {
  6739. //check Transaction active
  6740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6741. {
  6742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6743. {
  6744. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6745. {
  6746. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6747. {
  6748. match = TRUE;
  6749. GunNO = gun_index;
  6750. }
  6751. }
  6752. }// END FOR CHAdeMO_QUANTITY
  6753. for (int index = 0; index < CCS_QUANTITY; index++)
  6754. {
  6755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6756. {
  6757. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6758. {
  6759. match = TRUE;
  6760. GunNO = gun_index;
  6761. }
  6762. }
  6763. }// END FOR CCS_QUANTITY
  6764. for (int index = 0; index < GB_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6767. {
  6768. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6769. {
  6770. match = TRUE;
  6771. GunNO = gun_index;
  6772. }
  6773. }
  6774. }// END FOR GB_QUANTITY
  6775. }
  6776. else
  6777. {
  6778. for (int index = 0; index < AC_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6781. {
  6782. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6783. {
  6784. match = TRUE;
  6785. GunNO = gun_index;
  6786. }
  6787. }
  6788. }// END FOR CHAdeMO_QUANTITY
  6789. }// END FOR AC ELSE
  6790. }// CHECK IF ResponseTransactionId == transactionIdInt
  6791. }//END FOR
  6792. if( match == TRUE)
  6793. {
  6794. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6796. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6797. }
  6798. else
  6799. {
  6800. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6801. }
  6802. }
  6803. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6804. return result;
  6805. }
  6806. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6807. {
  6808. mtrace();
  6809. int result = FAIL;
  6810. int connectorIdInt=0, reservationIdInt=0;
  6811. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6812. char comfirmstr[20]={0};
  6813. char sstr[180]={ 0 };
  6814. int c = 0;
  6815. char *loc;
  6816. //char *ptr;
  6817. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6818. //***(1)connectorId ****/
  6819. c=0;
  6820. loc = strstr(payload, "connectorId");
  6821. memset(sstr ,0, sizeof(sstr) );
  6822. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6823. {
  6824. sstr[c] = loc[strlen("connectorId")+2+c];
  6825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6826. c++;
  6827. }
  6828. sstr[c] = '\0';
  6829. connectorIdInt = atoi(sstr);
  6830. //***(2)expiryDate ****/
  6831. loc = strstr(payload, "expiryDate");
  6832. memset(sstr ,0, sizeof(sstr) );
  6833. c = 0;
  6834. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6835. {
  6836. sstr[c] = loc[3+strlen("expiryDate")+c];
  6837. c++;
  6838. }
  6839. sstr[c] = '\0';
  6840. strcpy(expiryDatestr, sstr);
  6841. //***(3)idTag ****/
  6842. loc = strstr(payload, "idTag");
  6843. memset(sstr ,0, sizeof(sstr) );
  6844. c = 0;
  6845. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6846. {
  6847. sstr[c] = loc[3+strlen("idTag")+c];
  6848. c++;
  6849. }
  6850. sstr[c] = '\0';
  6851. strcpy(idTagstr, sstr);
  6852. //***(4)parentIdTag ****/
  6853. loc = strstr(payload, "parentIdTag");
  6854. memset(sstr ,0, sizeof(sstr) );
  6855. c = 0;
  6856. if(loc == NULL)
  6857. {
  6858. strcpy(parentIdTagstr, "");
  6859. }
  6860. else
  6861. {
  6862. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6863. {
  6864. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6865. c++;
  6866. }
  6867. sstr[c] = '\0';
  6868. strcpy(parentIdTagstr, sstr);
  6869. }
  6870. //***(5)reservationId ****/
  6871. c=0;
  6872. loc = strstr(payload, "reservationId");
  6873. memset(sstr ,0, sizeof(sstr) );
  6874. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6875. {
  6876. sstr[c] = loc[strlen("reservationId")+2+c];
  6877. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6878. c++;
  6879. }
  6880. sstr[c] = '\0';
  6881. reservationIdInt = atoi(sstr);
  6882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6883. if(reservationIdInt == 0)
  6884. {
  6885. //reservationId's value can not be 0
  6886. //strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6887. goto end;
  6888. }
  6889. /*
  6890. enum SYSTEM_STATUS
  6891. {
  6892. SYS_MODE_BOOTING = 0,
  6893. SYS_MODE_IDLE = 1,
  6894. SYS_MODE_AUTHORIZING = 2,
  6895. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6896. SYS_MODE_REASSIGN = 4,
  6897. SYS_MODE_PREPARING = 5,
  6898. SYS_MODE_PREPARE_FOR_EV = 6,
  6899. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6900. SYS_MODE_CHARGING = 8,
  6901. SYS_MODE_TERMINATING = 9,
  6902. SYS_MODE_COMPLETE = 10,
  6903. SYS_MODE_ALARM = 11,
  6904. SYS_MODE_FAULT = 12,
  6905. SYS_MODE_RESERVATION = 13,
  6906. SYS_MODE_BOOKING = 14,
  6907. SYS_MODE_MAINTAIN = 15,
  6908. SYS_MODE_DEBUG = 16,
  6909. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6910. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6911. SYS_MODE_UPDATE = 19
  6912. };
  6913. */
  6914. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6915. {
  6916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6917. goto end;
  6918. }
  6919. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6920. {
  6921. //check Transaction active
  6922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6923. {
  6924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6927. {
  6928. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6929. {
  6930. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6931. {
  6932. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6933. {
  6934. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6936. }
  6937. 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'))
  6938. {
  6939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6940. }
  6941. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  6942. {
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6944. }
  6945. else
  6946. {
  6947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6948. }
  6949. }
  6950. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6951. {
  6952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6953. }
  6954. }
  6955. else
  6956. {
  6957. //replace reservation
  6958. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6960. }
  6961. }
  6962. } // END FOR CHAdeMO_QUANTITY
  6963. for (int index = 0; index < CCS_QUANTITY; index++)
  6964. {
  6965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6966. {
  6967. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6968. {
  6969. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6971. {
  6972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6973. {
  6974. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6976. }
  6977. 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'))
  6978. {
  6979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6980. }
  6981. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  6982. {
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6984. }
  6985. else
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6988. }
  6989. }
  6990. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6991. {
  6992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6993. }
  6994. }
  6995. else
  6996. {
  6997. //replace reservation
  6998. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7000. }
  7001. }
  7002. } // END FOR CCS_QUANTITY
  7003. for (int index = 0; index < GB_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7006. {
  7007. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7008. {
  7009. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7010. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7011. {
  7012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7013. {
  7014. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7016. }
  7017. 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'))
  7018. {
  7019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7020. }
  7021. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7022. {
  7023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7024. }
  7025. else
  7026. {
  7027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7028. }
  7029. }
  7030. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7031. {
  7032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7033. }
  7034. }
  7035. else
  7036. {
  7037. //replace reservation
  7038. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7040. }
  7041. }
  7042. }// END FOR GB_QUANTITY
  7043. }
  7044. else
  7045. {
  7046. for (int index = 0; index < AC_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7049. {
  7050. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7051. {
  7052. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7054. {
  7055. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7056. {
  7057. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7059. }
  7060. 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'))
  7061. {
  7062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7063. }
  7064. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7065. {
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7067. }
  7068. else
  7069. {
  7070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7071. }
  7072. }
  7073. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7074. {
  7075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7076. }
  7077. }
  7078. else
  7079. {
  7080. //replace reservation
  7081. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7083. }
  7084. }
  7085. } // END FOR AC_QUANTITY
  7086. }//END FOR AC ELSE
  7087. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7088. }
  7089. else if(connectorIdInt == 0)
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7092. {
  7093. //check Transaction active
  7094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7095. {
  7096. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7097. {
  7098. 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'))
  7099. {
  7100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7101. goto end;
  7102. }
  7103. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7104. {
  7105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7106. goto end;
  7107. }
  7108. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7109. {
  7110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7111. goto end;
  7112. }
  7113. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7114. {
  7115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7116. goto end;
  7117. }
  7118. }
  7119. }// END FOR CHAdeMO_QUANTITY
  7120. for (int index = 0; index < CCS_QUANTITY; index++)
  7121. {
  7122. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7123. {
  7124. 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'))
  7125. {
  7126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7127. }
  7128. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7129. {
  7130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7131. }
  7132. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7135. }
  7136. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7137. {
  7138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7139. }
  7140. }
  7141. } // END FOR CCS_QUANTITY
  7142. for (int index = 0; index < GB_QUANTITY; index++)
  7143. {
  7144. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7145. {
  7146. 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'))
  7147. {
  7148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7149. }
  7150. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7151. {
  7152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7153. }
  7154. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7155. {
  7156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7157. }
  7158. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7159. {
  7160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7161. }
  7162. }
  7163. } // END FOR GB_QUANTITY
  7164. }
  7165. else
  7166. {
  7167. for (int index = 0; index < AC_QUANTITY; index++)
  7168. {
  7169. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7170. {
  7171. 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'))
  7172. {
  7173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7174. goto end;
  7175. }
  7176. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7177. {
  7178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7179. goto end;
  7180. }
  7181. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7182. {
  7183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7184. goto end;
  7185. }
  7186. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7187. {
  7188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7189. goto end;
  7190. }
  7191. }
  7192. }// END FOR AC_QUANTITY
  7193. }
  7194. //The connectorId is 0
  7195. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7197. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7198. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7199. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7200. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7201. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7202. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7203. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7204. result = TRUE;
  7205. return result;
  7206. }
  7207. else
  7208. {
  7209. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7210. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7211. }
  7212. if(strcmp(comfirmstr,"Accepted") == 0)
  7213. {
  7214. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7215. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7216. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7217. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7218. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7219. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7220. result = TRUE;
  7221. return result;
  7222. }
  7223. end:
  7224. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7225. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7226. return result;
  7227. }
  7228. int handleResetRequest(char *uuid, char *payload)
  7229. {
  7230. mtrace();
  7231. int result = FAIL;
  7232. char sstr[10]={0};
  7233. char typestr[10]={0};
  7234. char comfirmstr[20]={0};
  7235. int c = 0;
  7236. char *loc;
  7237. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7238. DEBUG_INFO("handleResetRequest ...\n");
  7239. loc = strstr(payload, "type");
  7240. memset(sstr ,0, sizeof(sstr) );
  7241. c = 0;
  7242. while (loc[3+strlen("type")+c] != '\"')
  7243. {
  7244. sstr[c] = loc[3+strlen("type")+c];
  7245. c++;
  7246. }
  7247. sstr[c] = '\0';
  7248. strcpy(typestr,sstr);
  7249. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7250. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7251. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7252. {
  7253. //check Transaction active
  7254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7255. {
  7256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7259. {
  7260. //0: unplug, 1: Plug-in
  7261. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7262. }
  7263. }
  7264. for (int index = 0; index < CCS_QUANTITY; index++)
  7265. {
  7266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7267. {
  7268. //0: unplug, 1: Plug-in
  7269. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7270. }
  7271. }
  7272. for (int index = 0; index < GB_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7275. {
  7276. //0: unplug, 1: Plug-in
  7277. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7278. }
  7279. }
  7280. }
  7281. else
  7282. {
  7283. for (int index = 0; index < AC_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7286. {
  7287. //0: unplug, 1: Plug-in
  7288. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7289. }
  7290. }
  7291. }// END FOR AC ELSE
  7292. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7293. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7294. result = TRUE;
  7295. return result;
  7296. }
  7297. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7298. {
  7299. //check Transaction active
  7300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7301. {
  7302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7303. {
  7304. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7305. {
  7306. //0: unplug, 1: Plug-in
  7307. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7308. }
  7309. }
  7310. for (int index = 0; index < CCS_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7313. {
  7314. //0: unplug, 1: Plug-in
  7315. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7316. }
  7317. }
  7318. for (int index = 0; index < GB_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7321. {
  7322. //0: unplug, 1: Plug-in
  7323. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7324. }
  7325. }
  7326. }
  7327. else
  7328. {
  7329. for (int index = 0; index < AC_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7332. {
  7333. //0: unplug, 1: Plug-in
  7334. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7335. }
  7336. }
  7337. }// END FOR AC ELSE
  7338. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7339. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7340. result = TRUE;
  7341. return result;
  7342. }
  7343. else
  7344. {
  7345. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7346. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7347. goto errorend;
  7348. }
  7349. errorend:
  7350. sendResetConfirmation(uuid, comfirmstr);
  7351. return result;
  7352. }
  7353. int handleSendLocalListRequest(char *uuid, char *payload)
  7354. {
  7355. mtrace();
  7356. int result = FAIL;
  7357. int listVersionInt;
  7358. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7359. char listsearch[]="listVersion";
  7360. char updateTypesearch[]="updateType";
  7361. char localAuthorizationListsearch[]="localAuthorizationList";
  7362. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7363. char CardList[500][160]={0};
  7364. char updateTypestr[15]={0};
  7365. char idTagstr[20]={0};
  7366. char parentIdTag[20]={0};
  7367. char expiryDate[30]={0};
  7368. char idTagstatus[16]={0};
  7369. int c = 0;
  7370. int i = 0;
  7371. char *delim1 = "}";
  7372. char * pch;
  7373. char *loc;
  7374. //char *ptr;
  7375. char comfirmstr[20];
  7376. //int n_localAuthorizations = 0;
  7377. int checkState_Faulted = FALSE;
  7378. DEBUG_INFO("handleSendLocalListRequest\n");
  7379. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7380. {
  7381. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7382. goto end;
  7383. }
  7384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7385. {
  7386. //check Charge Point state
  7387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7388. {
  7389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7390. {
  7391. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7392. }
  7393. }
  7394. for (int index = 0; index < CCS_QUANTITY; index++)
  7395. {
  7396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7397. {
  7398. checkState_Faulted = TRUE; //OCPP Status
  7399. }
  7400. }
  7401. for (int index = 0; index < GB_QUANTITY; index++)
  7402. {
  7403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7404. {
  7405. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7406. }
  7407. }
  7408. }
  7409. else
  7410. {
  7411. //check Charge Point state
  7412. for (int index = 0; index < AC_QUANTITY; index++)
  7413. {
  7414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7415. {
  7416. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7417. }
  7418. }
  7419. }// END FOR AC ELSE
  7420. if(checkState_Faulted == TRUE)
  7421. {
  7422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7423. goto end;
  7424. }
  7425. //listVersion
  7426. c = 0;
  7427. loc = strstr(payload, listsearch);
  7428. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7429. {
  7430. sstr[c] = loc[strlen("listVersion")+2+c];
  7431. c++;
  7432. }
  7433. sstr[c] = '\0';
  7434. listVersionInt = atoi(sstr);
  7435. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7436. //updateType
  7437. loc = strstr(payload, updateTypesearch);
  7438. c = 0;
  7439. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7440. {
  7441. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(updateTypestr, sstr);
  7446. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7447. //localAuthorizationList
  7448. memset(sstr ,0, sizeof(sstr) );
  7449. loc = strstr(payload, localAuthorizationListsearch);
  7450. if(loc != NULL) // localAuthorizationList is not NULL
  7451. {
  7452. //Check UpdateType
  7453. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7454. {
  7455. //Local list full update
  7456. printf("Local list full update.\n");
  7457. OCPP_getListVerion();
  7458. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7459. {
  7460. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7461. goto end;
  7462. }
  7463. OCPP_cleanLocalList();
  7464. }
  7465. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7466. {
  7467. //Local list different update
  7468. printf("Local list different update.\n");
  7469. OCPP_getListVerion();
  7470. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7471. {
  7472. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7473. goto end;
  7474. }
  7475. }
  7476. else
  7477. {
  7478. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7479. goto end;
  7480. }
  7481. c = 0;
  7482. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7483. {
  7484. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7486. c++;
  7487. }
  7488. sstr[c] = '\0';
  7489. //DEBUG_INFO("sstr=%s\n", sstr);
  7490. //parsing strings to words
  7491. i = 0;
  7492. pch = strtok(sstr,delim1);
  7493. while (pch != NULL)
  7494. {
  7495. strcpy(CardList[i], pch);
  7496. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7497. pch = strtok (NULL, delim1);
  7498. i = i + 1;
  7499. }
  7500. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7501. //local Authorizations List Numbers
  7502. //n_localAuthorizations = i;
  7503. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7504. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7505. c= 0;
  7506. while(c < i) // i is CardList Number
  7507. {
  7508. //Search "IdToken"
  7509. memset(sstr ,0, sizeof(sstr) );
  7510. loc = strstr(CardList[c], "idTag");
  7511. int j = 0;
  7512. while (loc[3+strlen("idTag")+j] != '\"')
  7513. {
  7514. sstr[j] = loc[3+strlen("idTag")+j];
  7515. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7516. j++;
  7517. }
  7518. sstr[j] = '\0';
  7519. strcpy(idTagstr, sstr);
  7520. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7521. //Search "expiryDate"
  7522. memset(sstr ,0, sizeof(sstr) );
  7523. loc = strstr(CardList[c], "expiryDate");
  7524. j = 0;
  7525. if(loc != NULL)
  7526. {
  7527. while (loc[3+strlen("expiryDate")+j] != '\"')
  7528. {
  7529. sstr[j] = loc[3+strlen("expiryDate")+j];
  7530. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7531. j++;
  7532. }
  7533. sstr[j] = '\0';
  7534. strcpy(expiryDate, sstr);
  7535. }
  7536. else
  7537. {
  7538. strcpy(expiryDate, "");
  7539. }
  7540. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7541. //Search "parentIdTag"
  7542. memset(sstr ,0, sizeof(sstr) );
  7543. loc = strstr(CardList[c], "parentIdTag");
  7544. j = 0;
  7545. if(loc != NULL)
  7546. {
  7547. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7548. {
  7549. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7550. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7551. j++;
  7552. }
  7553. sstr[j] = '\0';
  7554. strcpy(parentIdTag, sstr);
  7555. }
  7556. else
  7557. {
  7558. strcpy(parentIdTag, "");
  7559. }
  7560. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7561. //Search "status"
  7562. memset(sstr ,0, sizeof(sstr) );
  7563. loc = strstr(CardList[c], "status");
  7564. j = 0;
  7565. while (loc[3+strlen("status")+j] != '\"')
  7566. {
  7567. sstr[j] = loc[3+strlen("status")+j];
  7568. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7569. j++;
  7570. }
  7571. sstr[j] = '\0';
  7572. strcpy(idTagstatus, sstr);
  7573. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7574. OCPP_getIdTag(idTagstr);
  7575. //OCPP_getIdTag("test"); For Test
  7576. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7577. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7578. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7579. {
  7580. //Local list full update
  7581. DEBUG_INFO("Local list full update.\n");
  7582. // update list
  7583. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7584. //DEBUG_INFO("Local list full update. 1\n");
  7585. //OCPP_get_TableAuthlocalAllData();
  7586. //DEBUG_INFO("Local list full update. 2\n");
  7587. }
  7588. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7589. {
  7590. #if 0
  7591. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7592. {
  7593. //OCPP_deleteIdTag(idTagstr);
  7594. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7595. }
  7596. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7597. {
  7598. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7599. }
  7600. #endif
  7601. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7602. }
  7603. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7604. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7605. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7606. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7607. c++;
  7608. }
  7609. }
  7610. else
  7611. {
  7612. //Check UpdateType
  7613. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7614. {
  7615. //Local list full update
  7616. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7617. OCPP_cleanLocalList();
  7618. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7619. goto end;
  7620. }
  7621. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7622. {
  7623. //Local list different update
  7624. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7626. goto end;
  7627. }
  7628. }
  7629. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7630. end:
  7631. sendSendLocalListConfirmation(uuid, comfirmstr);
  7632. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7633. return result;
  7634. }
  7635. #define MAX 200
  7636. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7637. {
  7638. mtrace();
  7639. int result = FAIL;
  7640. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7641. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7642. char chargingProfilePurposeStr[30]={0};
  7643. char chargingProfileKindStr[16]={0};
  7644. char recurrencyKindStr[10]={0};
  7645. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7646. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7647. int chargingSchedulePeriodCount = 0;
  7648. //int updateflag = FALSE;
  7649. char comfirmstr[20]={0};
  7650. int meet= FALSE;
  7651. char sstr[10]={0};
  7652. int c = 0;
  7653. char *loc;
  7654. FILE *fptr1;//, *fptr2;
  7655. //int lno=0;//, linectr = 0;
  7656. //int modifyflag = FALSE;
  7657. char filename[MAX]={0};
  7658. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7659. //int resultRename=0;
  7660. char rmFileCmd[50]={0};
  7661. char tempchargingProfilePurposeStr[30]={0};
  7662. char word[1600]={0};
  7663. int n_chargingProfile = 0;
  7664. //[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}}}]
  7665. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7666. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7667. //*********************connectorId***************************/
  7668. loc = strstr(payload, "connectorId");
  7669. c = 0;
  7670. memset(sstr ,0, sizeof(sstr) );
  7671. while (loc[strlen("connectorId")+2+c] != ',')
  7672. {
  7673. sstr[c] = loc[strlen("connectorId")+2+c];
  7674. c++;
  7675. }
  7676. sstr[c] = '\0';
  7677. connectorIdInt = atoi(sstr);
  7678. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7679. {
  7680. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7681. }
  7682. else
  7683. {
  7684. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7685. }
  7686. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7687. //*********************chargingProfileId***************************/
  7688. loc = strstr(payload, "chargingProfileId");
  7689. c = 0;
  7690. memset(sstr ,0, sizeof(sstr) );
  7691. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7692. {
  7693. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7694. c++;
  7695. }
  7696. sstr[c] = '\0';
  7697. chargingProfileIdInt = atoi(sstr);
  7698. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7699. {
  7700. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7701. }
  7702. else
  7703. {
  7704. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7705. }
  7706. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7707. //*********************transactionId***************************/
  7708. loc = strstr(payload, "transactionId");
  7709. if(loc != NULL)
  7710. {
  7711. c = 0;
  7712. memset(sstr ,0, sizeof(sstr) );
  7713. while (loc[strlen("transactionId")+2+c] != ',')
  7714. {
  7715. sstr[c] = loc[strlen("transactionId")+2+c];
  7716. c++;
  7717. }
  7718. sstr[c] = '\0';
  7719. transactionIdInt = atoi(sstr);
  7720. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7721. {
  7722. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7723. }
  7724. else
  7725. {
  7726. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7727. }
  7728. }
  7729. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7730. //*********************stackLevel***************************/
  7731. loc = strstr(payload, "stackLevel");
  7732. c = 0;
  7733. memset(sstr ,0, sizeof(sstr) );
  7734. while (loc[strlen("stackLevel")+2+c] != ',')
  7735. {
  7736. sstr[c] = loc[strlen("stackLevel")+2+c];
  7737. c++;
  7738. }
  7739. sstr[c] = '\0';
  7740. stackLevelInt = atoi(sstr);
  7741. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7742. {
  7743. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7744. }
  7745. else
  7746. {
  7747. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7748. }
  7749. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7750. //*********************chargingProfilePurpose***************************/
  7751. loc = strstr(payload, "chargingProfilePurpose");
  7752. c = 0;
  7753. memset(sstr ,0, sizeof(sstr) );
  7754. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7755. {
  7756. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7758. c++;
  7759. }
  7760. sstr[c] = '\0';
  7761. strcpy(chargingProfilePurposeStr,sstr);
  7762. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7763. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7764. {
  7765. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7766. }
  7767. else
  7768. {
  7769. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7770. }
  7771. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7772. //*********************chargingProfileKind***************************/
  7773. loc = strstr(payload, "chargingProfileKind");
  7774. c = 0;
  7775. memset(sstr ,0, sizeof(sstr) );
  7776. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7777. {
  7778. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7779. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7780. c++;
  7781. }
  7782. sstr[c] = '\0';
  7783. strcpy(chargingProfileKindStr,sstr);
  7784. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7785. {
  7786. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7787. }
  7788. else
  7789. {
  7790. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7791. }
  7792. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7793. //*********************recurrencyKind***************************/
  7794. loc = strstr(payload, "recurrencyKind");
  7795. if(loc != NULL)
  7796. {
  7797. c = 0;
  7798. memset(sstr ,0, sizeof(sstr) );
  7799. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7800. {
  7801. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7803. c++;
  7804. }
  7805. sstr[c] = '\0';
  7806. strcpy(recurrencyKindStr,sstr);
  7807. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7808. {
  7809. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7810. }
  7811. else
  7812. {
  7813. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7814. }
  7815. }
  7816. else
  7817. {
  7818. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7819. {
  7820. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7821. }
  7822. else
  7823. {
  7824. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7825. }
  7826. }
  7827. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7828. //*********************validFrom***************************/
  7829. loc = strstr(payload, "validFrom");
  7830. if(loc != NULL)
  7831. {
  7832. c = 0;
  7833. memset(sstr ,0, sizeof(sstr) );
  7834. while (loc[3+strlen("validFrom")+c] != '\"')
  7835. {
  7836. sstr[c] = loc[3+strlen("validFrom")+c];
  7837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7838. c++;
  7839. }
  7840. sstr[c] = '\0';
  7841. strcpy(validFromStr,sstr);
  7842. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7843. {
  7844. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7845. }
  7846. else
  7847. {
  7848. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7849. }
  7850. }
  7851. else
  7852. {
  7853. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7854. {
  7855. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7856. }
  7857. else
  7858. {
  7859. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7860. }
  7861. }
  7862. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7863. //*********************validTo***************************/
  7864. loc = strstr(payload, "validTo");
  7865. if(loc != NULL)
  7866. {
  7867. c = 0;
  7868. memset(sstr ,0, sizeof(sstr) );
  7869. while (loc[3+strlen("validTo")+c] != '\"')
  7870. {
  7871. sstr[c] = loc[3+strlen("validTo")+c];
  7872. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7873. c++;
  7874. }
  7875. sstr[c] = '\0';
  7876. strcpy(validToStr,sstr);
  7877. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7878. {
  7879. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7880. }
  7881. else
  7882. {
  7883. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7884. }
  7885. }
  7886. else
  7887. {
  7888. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7889. {
  7890. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7891. }
  7892. else
  7893. {
  7894. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7895. }
  7896. }
  7897. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7898. //*********************duration***************************/
  7899. loc = strstr(payload, "duration");
  7900. if(loc != NULL)
  7901. {
  7902. c = 0;
  7903. memset(sstr ,0, sizeof(sstr) );
  7904. while (loc[strlen("duration")+2+c] != ',')
  7905. {
  7906. sstr[c] = loc[strlen("duration")+2+c];
  7907. c++;
  7908. }
  7909. sstr[c] = '\0';
  7910. durationInt = atoi(sstr);
  7911. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7912. {
  7913. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7914. }
  7915. else
  7916. {
  7917. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7918. }
  7919. }
  7920. else
  7921. {
  7922. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7923. {
  7924. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7925. }
  7926. else
  7927. {
  7928. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7929. }
  7930. }
  7931. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7932. //*********************startSchedule***************************/
  7933. loc = strstr(payload, "startSchedule");
  7934. if(loc != NULL)
  7935. {
  7936. c = 0;
  7937. memset(sstr ,0, sizeof(sstr) );
  7938. while (loc[3+strlen("startSchedule")+c] != '\"')
  7939. {
  7940. sstr[c] = loc[3+strlen("startSchedule")+c];
  7941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7942. c++;
  7943. }
  7944. sstr[c] = '\0';
  7945. strcpy(startScheduleStr,sstr);
  7946. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7947. {
  7948. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7949. }
  7950. else
  7951. {
  7952. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7953. }
  7954. }
  7955. else
  7956. {
  7957. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7958. {
  7959. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7960. }
  7961. else
  7962. {
  7963. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7964. }
  7965. }
  7966. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7967. //*********************chargingRateUnit***************************/
  7968. loc = strstr(payload, "chargingRateUnit");
  7969. if(loc != NULL)
  7970. {
  7971. c = 0;
  7972. memset(sstr ,0, sizeof(sstr) );
  7973. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7974. {
  7975. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7977. c++;
  7978. }
  7979. sstr[c] = '\0';
  7980. strcpy(chargingRateUnitStr,sstr);
  7981. #if 0
  7982. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7983. {
  7984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7985. goto end;
  7986. }
  7987. #endif
  7988. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7989. {
  7990. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7991. }
  7992. else
  7993. {
  7994. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7995. }
  7996. }
  7997. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7998. //****************chargingSchedulePeriod count start*******************/
  7999. int what_len = strlen("startPeriod");
  8000. char tempChargingProfile[1000]={0};
  8001. strcpy(tempChargingProfile,(const char*)payload);
  8002. char *where = tempChargingProfile;
  8003. if (what_len)
  8004. {
  8005. while ((where = strstr(where, "startPeriod"))) {
  8006. where += what_len;
  8007. chargingSchedulePeriodCount++;
  8008. }
  8009. }
  8010. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8011. {
  8012. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8013. goto end;
  8014. }
  8015. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8016. //where = payload;
  8017. int templength = 0;
  8018. //int searchstart = 0;
  8019. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8020. {
  8021. //****************startPeriod*******************/
  8022. c=0;
  8023. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8024. memset(sstr ,0, sizeof(sstr) );
  8025. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8026. {
  8027. sstr[c] = loc[strlen("startPeriod")+2+c];
  8028. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8029. c++;
  8030. }
  8031. sstr[c] = '\0';
  8032. startPeriodInt[periodNums] = atoi(sstr);
  8033. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8034. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8035. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8036. {
  8037. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8038. }
  8039. else
  8040. {
  8041. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8042. }
  8043. templength = strlen("startPeriod")+2+c;
  8044. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8045. //****************limit*******************/
  8046. c=0;
  8047. loc = strstr(tempChargingProfile + templength, "limit");
  8048. memset(sstr ,0, sizeof(sstr) );
  8049. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8050. {
  8051. sstr[c] = loc[strlen("limit")+2+c];
  8052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8053. c++;
  8054. }
  8055. sstr[c] = '\0';
  8056. limitflaot[periodNums] = atof(sstr);
  8057. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8058. {
  8059. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8060. }
  8061. else
  8062. {
  8063. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8064. }
  8065. templength = templength + strlen("limit")+2+c;
  8066. //****************numberPhases*******************/
  8067. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8068. if(loc != NULL)
  8069. {
  8070. c=0;
  8071. memset(sstr ,0, sizeof(sstr) );
  8072. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8073. {
  8074. sstr[c] = loc[strlen("numberPhases")+2+c];
  8075. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8076. c++;
  8077. }
  8078. sstr[c] = '\0';
  8079. numberPhasesInt[periodNums] = atoi(sstr);
  8080. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8081. {
  8082. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8083. }
  8084. else
  8085. {
  8086. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8087. }
  8088. templength = templength + strlen("numberPhases")+2+c;
  8089. }
  8090. //where = loc;
  8091. }
  8092. //****************chargingSchedulePeriod count end*******************/
  8093. //*********************minChargingRate***************************/
  8094. loc = strstr(payload, "minChargingRate");
  8095. if(loc != NULL)
  8096. {
  8097. c = 0;
  8098. memset(sstr ,0, sizeof(sstr) );
  8099. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8100. {
  8101. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8102. c++;
  8103. }
  8104. sstr[c] = '\0';
  8105. minChargingRateFloat = atof(sstr);
  8106. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8107. {
  8108. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8109. }
  8110. else
  8111. {
  8112. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8113. }
  8114. }
  8115. else
  8116. {
  8117. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8118. {
  8119. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8120. }
  8121. else
  8122. {
  8123. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8124. }
  8125. }
  8126. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8127. {
  8128. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8129. if(connectorIdInt != 0)
  8130. {
  8131. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8132. goto end;
  8133. }
  8134. strcpy(filename, ChargePointMaxProfile_JSON );
  8135. fptr1 = fopen(filename, "r");
  8136. if (!fptr1)
  8137. {
  8138. //file not exist
  8139. DEBUG_INFO("Unable to open the input file!!\n");
  8140. fptr1 = fopen(filename, "w+");
  8141. }
  8142. else
  8143. {
  8144. //Check Charging Profile Count
  8145. while(fscanf(fptr1, "%s", word) != EOF)
  8146. {
  8147. //DEBUG_INFO("word=%s\n",word);
  8148. if(strstr(word, "chargingProfileId")!= NULL)
  8149. {
  8150. //DEBUG_INFO("test chargingProfileId \n");
  8151. n_chargingProfile = n_chargingProfile + 1;
  8152. //DEBUG_INFO("chargingProfileId Found\n");
  8153. }
  8154. }
  8155. }
  8156. fclose(fptr1);
  8157. }
  8158. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8159. {
  8160. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8161. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8162. {
  8163. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8164. goto end;
  8165. }
  8166. memset(filename, 0, sizeof filename);
  8167. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8168. fptr1 = fopen(filename, "r");
  8169. if (!fptr1)
  8170. {
  8171. //file not exist
  8172. //DEBUG_INFO("Unable to open the input file!!\n");
  8173. fptr1 = fopen(filename, "w+");
  8174. }
  8175. else
  8176. {
  8177. //Check Charging Profile Count
  8178. while(fscanf(fptr1, "%s", word) != EOF)
  8179. {
  8180. //DEBUG_INFO("word=%s\n",word);
  8181. if(strstr(word, "chargingProfileId")!= NULL)
  8182. {
  8183. //DEBUG_INFO("test chargingProfileId \n");
  8184. n_chargingProfile = n_chargingProfile + 1;
  8185. //DEBUG_INFO("chargingProfileId Found\n");
  8186. }
  8187. }
  8188. }
  8189. fclose(fptr1);
  8190. }
  8191. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8192. {
  8193. //printf("set chargingProfile 1-4\n");
  8194. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8195. //check Transaction active
  8196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8197. {
  8198. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8199. {
  8200. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8201. {
  8202. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8203. {
  8204. meet = TRUE;
  8205. break;
  8206. }
  8207. }
  8208. }
  8209. }
  8210. for (int index = 0; index < CCS_QUANTITY; index++)
  8211. {
  8212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8213. {
  8214. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8215. {
  8216. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8217. {
  8218. meet = TRUE;
  8219. break;
  8220. }
  8221. }
  8222. }
  8223. }
  8224. for (int index = 0; index < GB_QUANTITY; index++)
  8225. {
  8226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8227. {
  8228. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8229. {
  8230. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8231. {
  8232. meet = TRUE;
  8233. break;
  8234. }
  8235. }
  8236. }
  8237. }
  8238. for (int index = 0; index < AC_QUANTITY; index++)
  8239. {
  8240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  8241. {
  8242. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8243. {
  8244. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8245. {
  8246. meet = TRUE;
  8247. break;
  8248. }
  8249. }
  8250. }
  8251. }
  8252. if(meet == FALSE)
  8253. {
  8254. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8255. goto end;
  8256. }
  8257. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8258. {
  8259. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8260. goto end;
  8261. }
  8262. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8263. fptr1 = fopen(filename, "r");
  8264. if (!fptr1)
  8265. {
  8266. //file not exist
  8267. DEBUG_INFO("Unable to open the input file!!\n");
  8268. fptr1 = fopen(filename, "w+");
  8269. }
  8270. else
  8271. {
  8272. //Check Charging Profile Count
  8273. while(fscanf(fptr1, "%s", word) != EOF)
  8274. {
  8275. //DEBUG_INFO("word=%s\n",word);
  8276. if(strstr(word, "chargingProfileId")!= NULL)
  8277. {
  8278. //DEBUG_INFO("test chargingProfileId \n");
  8279. n_chargingProfile = n_chargingProfile + 1;
  8280. //DEBUG_INFO("chargingProfileId Found\n");
  8281. }
  8282. }
  8283. }
  8284. fclose(fptr1);
  8285. }
  8286. // Check ChargeProfileMaxStackLevel
  8287. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8288. {
  8289. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8290. goto end;
  8291. }
  8292. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8293. {
  8294. int i = 0;
  8295. char fnametemp[200]={0};
  8296. n_chargingProfile = 0;
  8297. //Check ChargePointMaxProfile.json exit
  8298. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8299. {
  8300. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8301. //Check Charging Profile Count
  8302. while(fscanf(fptr1, "%s", word) != EOF)
  8303. {
  8304. //DEBUG_INFO("word=%s\n",word);
  8305. if(strstr(word, "chargingProfileId")!= NULL)
  8306. {
  8307. //DEBUG_INFO("test chargingProfileId \n");
  8308. n_chargingProfile = n_chargingProfile + 1;
  8309. i = i + 1;
  8310. //DEBUG_INFO("chargingProfileId Found\n");
  8311. }
  8312. memset(word, 0, sizeof word);
  8313. }
  8314. fclose(fptr1);
  8315. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8316. }
  8317. //Check TxDefaultProfile_0.json exit
  8318. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8319. {
  8320. i = 0;
  8321. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8322. //Check Charging Profile Count
  8323. while(fscanf(fptr1, "%s", word) != EOF)
  8324. {
  8325. //DEBUG_INFO("word=%s\n",word);
  8326. if(strstr(word, "chargingProfileId")!= NULL)
  8327. {
  8328. //DEBUG_INFO("test chargingProfileId \n");
  8329. n_chargingProfile = n_chargingProfile + 1;
  8330. i = i + 1;
  8331. //DEBUG_INFO("chargingProfileId Found\n");
  8332. }
  8333. memset(word, 0, sizeof word);
  8334. }
  8335. fclose(fptr1);
  8336. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8337. }
  8338. //Check TxDefaultProfile_%d.json
  8339. for(int j=1; j <= gunTotalNumber; j++)
  8340. {
  8341. memset(fnametemp, 0, sizeof fnametemp);
  8342. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8343. if((access(fnametemp,F_OK))!=-1)
  8344. {
  8345. i = 0;
  8346. fptr1 = fopen(fnametemp, "r");
  8347. //Check Charging Profile Count
  8348. while(fscanf(fptr1, "%s", word) != EOF)
  8349. {
  8350. //DEBUG_INFO("word=%s\n",word);
  8351. if(strstr(word, "chargingProfileId")!= NULL)
  8352. {
  8353. //DEBUG_INFO("test chargingProfileId \n");
  8354. n_chargingProfile = n_chargingProfile + 1;
  8355. i = i + 1;
  8356. //DEBUG_INFO("chargingProfileId Found\n");
  8357. }
  8358. memset(word, 0, sizeof word);
  8359. }
  8360. fclose(fptr1);
  8361. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8362. }
  8363. }
  8364. //Check TxProfile_%d.json
  8365. for(int j=1; j <= gunTotalNumber; j++)
  8366. {
  8367. memset(fnametemp, 0, sizeof fnametemp);
  8368. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8369. if((access(fnametemp,F_OK))!=-1)
  8370. {
  8371. i = 0;
  8372. fptr1 = fopen(fnametemp, "r");
  8373. //Check Charging Profile Count
  8374. while(fscanf(fptr1, "%s", word) != EOF)
  8375. {
  8376. //DEBUG_INFO("word=%s\n",word);
  8377. if(strstr(word, "chargingProfileId")!= NULL)
  8378. {
  8379. //DEBUG_INFO("test chargingProfileId \n");
  8380. n_chargingProfile = n_chargingProfile + 1;
  8381. i = i + 1;
  8382. //DEBUG_INFO("chargingProfileId Found\n");
  8383. }
  8384. memset(word, 0, sizeof word);
  8385. }
  8386. fclose(fptr1);
  8387. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8388. }
  8389. }
  8390. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8391. {
  8392. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8393. goto end;
  8394. }
  8395. }
  8396. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8397. //**********************************Write to File********************************************************/
  8398. FILE *infile;
  8399. FILE *outfile;
  8400. // open file for writing
  8401. infile = fopen (filename, "r");
  8402. outfile = fopen (tempfile, "w");
  8403. int d =0;
  8404. d = fgetc(infile);
  8405. //DEBUG_INFO("d:%d\n",d);
  8406. rewind(infile);
  8407. //*检测到文件结束标识返回1,否则返回0。*/
  8408. if(d == EOF)
  8409. {
  8410. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8411. fprintf(outfile,"%s\n",payload);
  8412. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8413. fclose(infile);
  8414. fclose(outfile);
  8415. sprintf(rmFileCmd,"rm -f %s",filename);
  8416. system(rmFileCmd);
  8417. rename(tempfile, filename);
  8418. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8419. //system(rmFileCmd);
  8420. }
  8421. else
  8422. {
  8423. char buf[1000]={0};
  8424. int ChargingProfileAdded = FALSE;
  8425. while (fgets(buf, sizeof(buf), infile) != NULL)
  8426. {
  8427. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8428. //*************************tempconnectorIdInt*********************************/
  8429. loc = strstr(buf, "connectorId");
  8430. c = 0;
  8431. memset(sstr ,0, sizeof(sstr) );
  8432. while (loc[strlen("connectorId")+2+c] != ',')
  8433. {
  8434. sstr[c] = loc[strlen("connectorId")+2+c];
  8435. c++;
  8436. }
  8437. sstr[c] = '\0';
  8438. tempconnectorIdInt = atoi(sstr);
  8439. //*************************tempchargingProfileIdInt*********************************/
  8440. loc = strstr(buf, "chargingProfileId");
  8441. c = 0;
  8442. memset(sstr ,0, sizeof(sstr) );
  8443. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8444. {
  8445. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8446. c++;
  8447. }
  8448. sstr[c] = '\0';
  8449. tempchargingProfileIdInt = atoi(sstr);
  8450. //*************************tempstackLevelInt*********************************/
  8451. loc = strstr(buf, "stackLevel");
  8452. c = 0;
  8453. memset(sstr ,0, sizeof(sstr) );
  8454. while (loc[strlen("stackLevel")+2+c] != ',')
  8455. {
  8456. sstr[c] = loc[strlen("stackLevel")+2+c];
  8457. c++;
  8458. }
  8459. sstr[c] = '\0';
  8460. tempstackLevelInt = atoi(sstr);
  8461. //*************************tempchargingProfilePurposeStr*********************************/
  8462. loc = strstr(payload, "chargingProfilePurpose");
  8463. c = 0;
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8466. {
  8467. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8469. c++;
  8470. }
  8471. sstr[c] = '\0';
  8472. strcpy(tempchargingProfilePurposeStr,sstr);
  8473. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8474. {
  8475. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8476. {
  8477. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8478. if(ChargingProfileAdded == FALSE)
  8479. {
  8480. fprintf(outfile,"%s\n",payload);
  8481. ChargingProfileAdded = TRUE;
  8482. }
  8483. }
  8484. else
  8485. {
  8486. if(tempstackLevelInt < stackLevelInt)
  8487. {
  8488. if(ChargingProfileAdded == FALSE)
  8489. {
  8490. fprintf(outfile,"%s\n",payload);
  8491. ChargingProfileAdded = TRUE;
  8492. fprintf(outfile,"%s\n",buf);
  8493. }
  8494. else
  8495. {
  8496. fprintf(outfile,"%s\n",buf);
  8497. }
  8498. }
  8499. else
  8500. {
  8501. if(ChargingProfileAdded == FALSE)
  8502. {
  8503. fprintf(outfile,"%s\n",buf);
  8504. fprintf(outfile,"%s\n",payload);
  8505. ChargingProfileAdded = TRUE;
  8506. }
  8507. else
  8508. {
  8509. fprintf(outfile,"%s\n",buf);
  8510. }
  8511. }
  8512. }
  8513. }
  8514. else
  8515. {
  8516. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8517. {
  8518. if(ChargingProfileAdded == FALSE)
  8519. {
  8520. fprintf(outfile,"%s\n",payload);
  8521. ChargingProfileAdded = TRUE;
  8522. fprintf(outfile,"%s\n",buf);
  8523. }
  8524. else
  8525. {
  8526. fprintf(outfile,"%s\n",buf);
  8527. }
  8528. }
  8529. else if(tempstackLevelInt < stackLevelInt)
  8530. {
  8531. if(ChargingProfileAdded == FALSE)
  8532. {
  8533. fprintf(outfile,"%s\n",payload);
  8534. ChargingProfileAdded = TRUE;
  8535. fprintf(outfile,"%s\n",buf);
  8536. }
  8537. else
  8538. {
  8539. fprintf(outfile,"%s\n",buf);
  8540. }
  8541. }
  8542. else
  8543. {
  8544. if(ChargingProfileAdded == FALSE)
  8545. {
  8546. fprintf(outfile,"%s\n",buf);
  8547. fprintf(outfile,"%s\n",payload);
  8548. ChargingProfileAdded = TRUE;
  8549. }
  8550. else
  8551. {
  8552. fprintf(outfile,"%s\n",buf);
  8553. }
  8554. }
  8555. }
  8556. } // end of while loop
  8557. fclose(infile);
  8558. fclose(outfile);
  8559. sprintf(rmFileCmd,"rm -f %s",filename);
  8560. system(rmFileCmd);
  8561. rename(tempfile, filename);
  8562. result = TRUE;
  8563. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8564. }
  8565. end:
  8566. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8567. return result;
  8568. return result;
  8569. }
  8570. int handleTriggerMessageRequest(char *uuid, char *payload)
  8571. {
  8572. mtrace();
  8573. int result = FAIL;
  8574. int connectorIdIsNULL = FALSE;
  8575. int connectorIdInt =0;
  8576. char sstr[40]={0};
  8577. char requestedMessagestr[40]={0};
  8578. char comfirmstr[20]={0};
  8579. int c = 0;
  8580. char *loc;
  8581. DEBUG_INFO("handleTriggerMessageRequest\n");
  8582. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8583. c = 0;
  8584. loc = strstr(payload, "requestedMessage");
  8585. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8586. {
  8587. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8588. c++;
  8589. }
  8590. sstr[c] = '\0';
  8591. strcpy(requestedMessagestr, sstr);
  8592. c = 0;
  8593. loc = strstr(payload, "connectorId");
  8594. if(loc == NULL)
  8595. {
  8596. connectorIdIsNULL = TRUE;
  8597. }
  8598. else
  8599. {
  8600. memset(sstr ,0, sizeof(sstr) );
  8601. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8602. {
  8603. sstr[c] = loc[strlen("connectorId")+2+c];
  8604. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8605. c++;
  8606. }
  8607. sstr[c] = '\0';
  8608. connectorIdInt = atoi(sstr);
  8609. }
  8610. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8611. {
  8612. //connectorIdInt = json_object_get_int(connectorId);
  8613. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8614. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8615. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8616. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8617. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8618. }
  8619. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8620. {
  8621. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8622. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8623. return TRUE;
  8624. }
  8625. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8626. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8627. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8628. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8629. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8630. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8631. {
  8632. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8633. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8634. return TRUE;
  8635. }
  8636. else
  8637. {
  8638. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8639. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8640. }
  8641. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8642. {
  8643. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8644. {
  8645. FirmwareStatusNotificationStatus = 3;
  8646. }
  8647. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8648. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8649. }
  8650. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8651. {
  8652. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8653. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8654. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8655. }
  8656. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8657. {
  8658. sendBootNotificationRequest();
  8659. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8660. }
  8661. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8662. {
  8663. sendHeartbeatRequest(connectorIdInt);
  8664. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8665. }
  8666. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8667. {
  8668. if(connectorIdIsNULL == FALSE)
  8669. {
  8670. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8671. {
  8672. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8673. sendMeterValuesRequest(connectorIdInt -1);
  8674. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8675. }
  8676. }
  8677. else
  8678. {
  8679. for(int idx=0;idx< gunTotalNumber;idx++)
  8680. {
  8681. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8682. sendMeterValuesRequest(idx);
  8683. }
  8684. }
  8685. }
  8686. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8687. {
  8688. if(connectorIdIsNULL == FALSE)
  8689. {
  8690. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8691. {
  8692. sendStatusNotificationRequest(connectorIdInt -1);
  8693. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8694. }
  8695. }
  8696. else
  8697. {
  8698. for(int idx=0;idx< gunTotalNumber;idx++)
  8699. sendStatusNotificationRequest(idx);
  8700. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8701. }
  8702. }
  8703. return result;
  8704. }
  8705. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8706. {
  8707. mtrace();
  8708. int result = FAIL;
  8709. char sstr[6]={0};
  8710. int connectorIdInt =0;
  8711. char comfirmstr[20]={0};
  8712. int c = 0;
  8713. char *loc;
  8714. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8715. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8716. c = 0;
  8717. loc = strstr(payload, "connectorId");
  8718. memset(sstr ,0, sizeof(sstr) );
  8719. while (loc[strlen("connectorId")+2+c] != '}')
  8720. {
  8721. sstr[c] = loc[strlen("connectorId")+2+c];
  8722. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8723. c++;
  8724. }
  8725. sstr[c] = '\0';
  8726. connectorIdInt = atoi(sstr);
  8727. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8728. if(gunTotalNumber == 0)
  8729. {
  8730. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8731. goto end;
  8732. }
  8733. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8734. {
  8735. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8736. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8737. goto end;
  8738. }
  8739. else
  8740. {
  8741. //check Transaction active
  8742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8743. {
  8744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8745. {
  8746. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8747. {
  8748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8749. }
  8750. }
  8751. for (int index = 0; index < CCS_QUANTITY; index++)
  8752. {
  8753. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8754. {
  8755. //stop Transaction
  8756. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8757. }
  8758. }
  8759. for (int index = 0; index < GB_QUANTITY; index++)
  8760. {
  8761. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8762. {
  8763. //stop Transaction
  8764. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8765. }
  8766. }
  8767. }
  8768. else
  8769. {
  8770. for (int index = 0; index < AC_QUANTITY; index++)
  8771. {
  8772. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8773. {
  8774. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8775. }
  8776. }
  8777. }// END FOR AC ELSE
  8778. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8779. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8780. result = TRUE;
  8781. return result;
  8782. }
  8783. end:
  8784. //json_object_put(obj); --- remove temporally
  8785. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8786. return result;
  8787. }
  8788. static char UpdateFirmwarepayloadData[300]={0};
  8789. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8790. {
  8791. mtrace();
  8792. int result = FAIL;
  8793. pthread_t t;
  8794. sendUpdateFirmwareConfirmation(uuid);
  8795. memset(UpdateFirmwarepayloadData, 0, 300);
  8796. strcpy(UpdateFirmwarepayloadData, payload);
  8797. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8798. ////pthread_join(t, NULL); //
  8799. //pthread_detach(t);
  8800. //sendUpdateFirmwareConfirmation(uuid);
  8801. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8802. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8803. return result;
  8804. }
  8805. void *UpdateFirmwareProcess(void *data)
  8806. {
  8807. pthread_detach(pthread_self());
  8808. mtrace();
  8809. int retriesInt =0, retryIntervalInt=0;
  8810. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8811. int port=0;
  8812. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8813. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8814. //char comfirmstr[20];
  8815. int isSuccess = 0;
  8816. char ftpbuf[200];
  8817. char temp[100];
  8818. char * pch;
  8819. int retriesISNULL=FALSE;
  8820. int retryInterval=FALSE;
  8821. int c = 0;
  8822. //int i = 0;
  8823. char *loc;
  8824. char sstr[300]={ 0 };
  8825. char str[300]={ 0 };
  8826. //char *str = (char*) data; // ? ?輸入資 ?
  8827. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8828. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8829. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8830. //***************location **************/
  8831. loc = strstr(str, "location");
  8832. memset(sstr ,0, sizeof(sstr) );
  8833. c = 0;
  8834. while (loc[3+strlen("location")+c] != '\"')
  8835. {
  8836. sstr[c] = loc[3+strlen("location")+c];
  8837. c++;
  8838. }
  8839. sstr[c] = '\0';
  8840. strcpy(locationstr, sstr);
  8841. //***************retries**************/
  8842. c = 0;
  8843. loc = strstr(str, "retries");
  8844. if(loc == NULL)
  8845. {
  8846. retriesISNULL=TRUE;
  8847. }
  8848. else
  8849. {
  8850. memset(sstr ,0, sizeof(sstr) );
  8851. while (loc[strlen("retries")+2+c] != ',')
  8852. {
  8853. sstr[c] = loc[strlen("retries")+2+c];
  8854. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8855. c++;
  8856. }
  8857. sstr[c] = '\0';
  8858. }
  8859. if(retriesISNULL == FALSE)
  8860. {
  8861. retriesInt = atoi(sstr);
  8862. }
  8863. //***************retrieveDate **************/
  8864. loc = strstr(str, "retrieveDate");
  8865. memset(sstr ,0, sizeof(sstr) );
  8866. c = 0;
  8867. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8868. {
  8869. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8870. c++;
  8871. }
  8872. sstr[c] = '\0';
  8873. strcpy(retrieveDatestr, sstr);
  8874. //***************retryInterval **************/
  8875. c = 0;
  8876. loc = strstr(str, "retryInterval");
  8877. memset(sstr ,0, sizeof(sstr) );
  8878. if(loc == NULL)
  8879. {
  8880. retryInterval=TRUE;
  8881. }
  8882. else
  8883. {
  8884. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8885. {
  8886. sstr[c] = loc[strlen("retryInterval")+2+c];
  8887. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8888. c++;
  8889. }
  8890. sstr[c] = '\0';
  8891. }
  8892. if(retryInterval==FALSE)
  8893. {
  8894. retryIntervalInt = atoi(sstr);
  8895. }
  8896. memset(ftppath, 0, sizeof(ftppath));
  8897. memset(path, 0, sizeof(path));
  8898. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8899. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8900. if(strncmp(locationstr,"http", 4) == 0)
  8901. {
  8902. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8903. protocol, host, path);
  8904. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8905. // protocol, user, password, host, path);
  8906. sprintf(ftppath,"/%s", path);
  8907. //DEBUG_INFO("protocol =%s\n",protocol);
  8908. //DEBUG_INFO("host =%s\n",host);
  8909. //DEBUG_INFO("path =%s\n",path);
  8910. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8911. int ftppathlen=strlen(ftppath);
  8912. int i=1;
  8913. char filenametemp[50];
  8914. while(i < ftppathlen)
  8915. {
  8916. int len=ftppathlen-i;
  8917. if(ftppath[len]== 47) // '/' ascll code: 47
  8918. {
  8919. DEBUG_INFO("compare '/' all right\n");
  8920. break;
  8921. }
  8922. i=i+1;
  8923. }
  8924. memset(filenametemp, 0, sizeof(filenametemp));
  8925. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8926. filenametemp[i+1] = 0;
  8927. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8928. do{
  8929. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8930. sleep(retryIntervalInt);
  8931. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8932. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8933. if(!isSuccess)
  8934. {
  8935. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8936. }
  8937. else
  8938. {
  8939. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8940. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8941. isUpdateRequest = TRUE;
  8942. }
  8943. }
  8944. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8945. {
  8946. memset(ftpbuf, 0, sizeof(ftpbuf));
  8947. memset(temp, 0, sizeof(temp));
  8948. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8949. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8950. int ftppathlen=strlen(ftpbuf);
  8951. int i=1;
  8952. char filenametemp[50];
  8953. while(i < ftppathlen)
  8954. {
  8955. int len=ftppathlen-i;
  8956. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8957. {
  8958. DEBUG_INFO(" compare '/' all right\n");
  8959. break;
  8960. }
  8961. i=i+1;
  8962. }
  8963. memset(filenametemp, 0, sizeof(filenametemp));
  8964. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8965. filenametemp[i+1] = 0;
  8966. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8967. pch=strchr(temp,'@');
  8968. if(pch==NULL)
  8969. {
  8970. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8971. protocol, host, &port, path);
  8972. strcpy(user,"anonymous");
  8973. strcpy(password,"");
  8974. }
  8975. else
  8976. {
  8977. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8978. protocol, user, password, host, &port, path);
  8979. }
  8980. sscanf(host,"%[^/]%s",host1, path1);
  8981. sprintf(ftppath,"%s", path1);
  8982. //DEBUG_INFO("protocol =%s\n",protocol);
  8983. //DEBUG_INFO("user =%s\n",user);
  8984. //DEBUG_INFO("password =%s\n",password);
  8985. //DEBUG_INFO("host1 =%s\n",host1);
  8986. //DEBUG_INFO("port =%d\n",port);
  8987. //DEBUG_INFO("path1 =%s\n",path1);
  8988. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8989. //ftpFile(host, user, password, port, ftppath, fname);
  8990. //download firmware pthred
  8991. if(port == 0)
  8992. {
  8993. port = 21;
  8994. }
  8995. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8996. do{
  8997. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8998. sleep(retryIntervalInt);
  8999. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9000. if(!isSuccess)
  9001. {
  9002. //BulldogUtil.sleepMs(interval*1000);
  9003. DEBUG_INFO("Update firmware request and download file fail.\n");
  9004. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9005. }
  9006. else
  9007. {
  9008. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9009. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9010. isUpdateRequest = TRUE;
  9011. }
  9012. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9013. }
  9014. else
  9015. {
  9016. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9017. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9018. }
  9019. pthread_exit(NULL);
  9020. }
  9021. //==========================================
  9022. // Handle server response routine
  9023. //==========================================
  9024. void handleAuthorizeResponse(char *payload, int gun_index)
  9025. {
  9026. mtrace();
  9027. char expiryDatestr[30]={0};
  9028. char parentIdTagstr[20]={0};
  9029. char statusstr[20]={0};
  9030. char expiryDatestrtemp[30]={0};
  9031. char parentIdTagstrtemp[20]={0};
  9032. char IdTagstrtemp[20]={0};
  9033. char statusstrtemp[20]={0};
  9034. int expiryDateISNULL=FALSE;
  9035. int parentIdTagISNULL=FALSE;
  9036. char sstr[160]={ 0 };
  9037. char* filename = AuthorizationCache_JSON;
  9038. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9039. int c = 0;
  9040. char *loc;
  9041. int resultRename=0;
  9042. int responseIdTagInfoAsZero= 0;
  9043. char rmFileCmd[50]={0};
  9044. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9045. //***********expiryDate*************/
  9046. loc = strstr(payload, "expiryDate");
  9047. memset(sstr ,0, sizeof(sstr) );
  9048. c = 0;
  9049. if(loc == NULL)
  9050. {
  9051. expiryDateISNULL = TRUE;
  9052. }
  9053. else
  9054. {
  9055. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9056. {
  9057. sstr[c] = loc[3+strlen("expiryDate")+c];
  9058. c++;
  9059. }
  9060. sstr[c] = '\0';
  9061. strcpy(expiryDatestr, sstr);
  9062. }
  9063. //***********parentIdTag*************/
  9064. loc = strstr(payload, "parentIdTag");
  9065. memset(sstr ,0, sizeof(sstr) );
  9066. c = 0;
  9067. if(loc == NULL)
  9068. {
  9069. parentIdTagISNULL = TRUE;
  9070. }
  9071. else
  9072. {
  9073. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9074. {
  9075. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9076. c++;
  9077. }
  9078. sstr[c] = '\0';
  9079. strcpy(parentIdTagstr, sstr);
  9080. }
  9081. //***********status*************/
  9082. loc = strstr(payload, "status");
  9083. memset(sstr ,0, sizeof(sstr) );
  9084. c = 0;
  9085. while (loc[3+strlen("status")+c] != '\"')
  9086. {
  9087. sstr[c] = loc[3+strlen("status")+c];
  9088. c++;
  9089. }
  9090. sstr[c] = '\0';
  9091. strcpy(statusstr, sstr);
  9092. if(expiryDateISNULL == FALSE)
  9093. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9094. if(parentIdTagISNULL == FALSE)
  9095. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9096. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9097. //Update idTag information to authorization cache if supproted
  9098. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9099. {
  9100. if((access(filename,F_OK))!=-1)
  9101. {
  9102. printf("AuthorizationCache exist.\n");
  9103. }
  9104. else
  9105. {
  9106. printf("AuthorizationCache not exist\n");
  9107. FILE *log = fopen(filename, "w+");
  9108. if(log == NULL)
  9109. {
  9110. printf("log is NULL\n");
  9111. goto out;
  9112. }
  9113. else
  9114. {
  9115. fclose(log);
  9116. }
  9117. }
  9118. FILE *infile;
  9119. FILE *outfile;
  9120. // open file for writing
  9121. infile = fopen (filename, "r");
  9122. outfile = fopen (tempfile, "w");
  9123. //*检测到文件结束标识返回1,否则返回0。*/
  9124. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9125. int c;
  9126. c = fgetc(infile);
  9127. //DEBUG_INFO("c:%d\n",c);
  9128. rewind(infile);
  9129. if(c == EOF)
  9130. {
  9131. DEBUG_INFO("Orignal File is NULL\n");
  9132. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9133. {
  9134. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9135. }
  9136. else
  9137. {
  9138. strcpy(expiryDatestrtemp, "");
  9139. }
  9140. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9141. {
  9142. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9143. }
  9144. else
  9145. {
  9146. //write Authorize IdTag
  9147. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9148. }
  9149. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9150. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9151. fclose(infile);
  9152. fclose(outfile);
  9153. sprintf(rmFileCmd,"rm -f %s",filename);
  9154. system(rmFileCmd);
  9155. resultRename = rename(tempfile, filename);
  9156. if(resultRename == 0)
  9157. {
  9158. printf("File renamed successfully");
  9159. }
  9160. else
  9161. {
  9162. printf("Error: unable to rename the file");
  9163. }
  9164. }
  9165. else
  9166. {
  9167. char buf[160]={0};
  9168. while (fgets(buf, sizeof(buf), infile) != NULL)
  9169. {
  9170. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9171. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9172. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9173. memset(statusstr, 0, sizeof(statusstrtemp));
  9174. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9175. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9176. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9177. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9178. //------------------IdTag-----------------------
  9179. loc = strstr(buf, "idTag");
  9180. memset(sstr ,0, sizeof(sstr) );
  9181. c = 0;
  9182. while (loc[3+strlen("idTag")+c] != '\"')
  9183. {
  9184. sstr[c] = loc[3+strlen("idTag")+c];
  9185. c++;
  9186. }
  9187. sstr[c] = '\0';
  9188. strcpy(IdTagstrtemp,sstr);
  9189. //*********************expiryDate***************/
  9190. loc = strstr(buf, "expiryDate");
  9191. memset(sstr ,0, sizeof(sstr) );
  9192. c = 0;
  9193. while (loc[3+strlen("expiryDate")+c] != '\"')
  9194. {
  9195. sstr[c] = loc[3+strlen("expiryDate")+c];
  9196. c++;
  9197. }
  9198. sstr[c] = '\0';
  9199. strcpy(expiryDatestr,sstr);
  9200. //*********************parentIdTag***************/
  9201. loc = strstr(buf, "parentIdTag");
  9202. memset(sstr ,0, sizeof(sstr) );
  9203. c = 0;
  9204. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9205. {
  9206. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9207. c++;
  9208. }
  9209. sstr[c] = '\0';
  9210. strcpy(parentIdTagstr,sstr);
  9211. //*********************status***************/
  9212. loc = strstr(buf, "status");
  9213. memset(sstr ,0, sizeof(sstr) );
  9214. c = 0;
  9215. while (loc[3+strlen("status")+c] != '\"')
  9216. {
  9217. sstr[c] = loc[3+strlen("status")+c];
  9218. c++;
  9219. }
  9220. sstr[c] = '\0';
  9221. strcpy(statusstr,sstr);
  9222. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9223. {
  9224. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9225. responseIdTagInfoAsZero = 1;
  9226. }
  9227. else
  9228. {
  9229. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9230. }
  9231. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9232. {
  9233. //modify item
  9234. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9235. {
  9236. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9237. }
  9238. else
  9239. {
  9240. strcpy(expiryDatestrtemp, "");
  9241. }
  9242. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9243. {
  9244. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9245. }
  9246. else
  9247. {
  9248. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9249. }
  9250. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9251. }
  9252. else
  9253. {
  9254. //wrie original item
  9255. strcpy(expiryDatestrtemp, expiryDatestr);
  9256. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9257. strcpy(statusstrtemp, statusstr);
  9258. }
  9259. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9260. }
  9261. fclose(infile);
  9262. fclose(outfile);
  9263. sprintf(rmFileCmd,"rm -f %s",filename);
  9264. system(rmFileCmd);
  9265. resultRename = rename(tempfile, filename);
  9266. if(resultRename == 0)
  9267. {
  9268. DEBUG_INFO("File renamed successfully");
  9269. }
  9270. else
  9271. {
  9272. DEBUG_INFO("Error: unable to rename the file");
  9273. }
  9274. }
  9275. }
  9276. out:
  9277. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9278. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9279. authorizeRetryTimes = 0;
  9280. }
  9281. char * strtrimc( char * s )
  9282. {
  9283. char * p1 = s;
  9284. char * p2 = s;
  9285. while(*p1 != '\0')
  9286. {
  9287. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9288. {
  9289. if(*p1 != ',')
  9290. {
  9291. p1 ++;
  9292. }
  9293. else
  9294. {
  9295. break;
  9296. }
  9297. }
  9298. if(*p1 != ',')
  9299. {
  9300. * p2 ++ = *p1 ++;
  9301. //printf("p2=%s\n",p2);
  9302. }
  9303. else
  9304. {
  9305. break;
  9306. }
  9307. }
  9308. *p2 = '\0';
  9309. return (s);
  9310. }
  9311. void handleBootNotificationResponse(char *payload, int gun_index)
  9312. {
  9313. mtrace();
  9314. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9315. char statusStr[12]={0};
  9316. char currentTimeStr[30]={0};
  9317. char *loc;
  9318. int intervalInt = 0;
  9319. int c = 0;
  9320. //double diff_t;
  9321. struct tm tp;
  9322. char buf[28]={0};
  9323. char timebuf[50]={0};
  9324. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9325. //*** interval ****/
  9326. c = 0;
  9327. loc = strstr(payload, "interval");
  9328. //printf("loc=%s\n",loc);
  9329. memset(sstr ,0, sizeof(sstr) );
  9330. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9331. {
  9332. sstr[c] = loc[strlen("interval")+2+c];
  9333. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9334. c++;
  9335. }
  9336. sstr[c] = '\0';
  9337. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9338. intervalInt = atoi(sstr);
  9339. //***status ****/
  9340. loc = strstr(payload, "status");
  9341. memset(sstr ,0, sizeof(sstr) );
  9342. c = 0;
  9343. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9344. {
  9345. sstr[c] = loc[3+strlen("status")+c];
  9346. c++;
  9347. }
  9348. sstr[c] = '\0';
  9349. strcpy(statusStr, sstr);
  9350. //***currentTime ****/
  9351. loc = strstr(payload, "currentTime");
  9352. //printf("loc=%s\n",loc);
  9353. memset(sstr ,0, sizeof(sstr) );
  9354. c = 0;
  9355. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9356. {
  9357. sstr[c] = loc[3+strlen("currentTime")+c];
  9358. c++;
  9359. }
  9360. sstr[c] = '\0';
  9361. strcpy(currentTimeStr, sstr);
  9362. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9363. HeartBeatWaitTime = BootNotificationInterval;
  9364. clientTime.Heartbeat=time((time_t*)NULL);
  9365. //write back to ShmOCPP16Data->BootNotification
  9366. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9367. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9368. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9369. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9370. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9371. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9372. {
  9373. server_sign = TRUE;
  9374. server_pending =FALSE;
  9375. }
  9376. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9377. {
  9378. server_pending = TRUE;
  9379. }
  9380. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9381. tp.tm_isdst = -1;
  9382. //time_t utc = mktime(&tp);
  9383. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9384. memset(timebuf, 0, sizeof timebuf);
  9385. sprintf(timebuf,"date -s '%s'",buf);
  9386. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9387. system(timebuf);
  9388. //==============================================
  9389. // RTC sync
  9390. //==============================================
  9391. system("/sbin/hwclock -w --systohc");
  9392. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9393. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9394. }
  9395. void handleDataTransferResponse(char *payload, int gun_index)
  9396. {
  9397. char sstr[160]={0};//sstr[200]={ 0 };
  9398. int c = 0;
  9399. char *loc;
  9400. DEBUG_INFO("handleDataTransferResponse ...\n");
  9401. loc = strstr(payload, "status");
  9402. printf("loc=%s\n",loc);
  9403. c = 0;
  9404. while (loc[3+strlen("status")+c] != '\"')
  9405. {
  9406. sstr[c] = loc[3+strlen("status")+c];
  9407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9408. c++;
  9409. }
  9410. sstr[c] = '\0';
  9411. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9412. }
  9413. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9414. {
  9415. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9416. //struct json_object *obj;
  9417. // obj = json_tokener_parse(payload);
  9418. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9419. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9420. //No fields are defined.
  9421. }
  9422. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9423. {
  9424. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9425. //struct json_object *obj;
  9426. // obj = json_tokener_parse(payload);
  9427. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9428. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9429. //No fields are defined.
  9430. }
  9431. void handleHeartbeatResponse(char *payload, int gun_index)
  9432. {
  9433. mtrace();
  9434. //double diff_t;
  9435. struct tm tp;
  9436. char buf[28]={0};
  9437. char timebuf[50]={0};
  9438. char sstr[30]={ 0 };
  9439. int c = 0;
  9440. char *loc;
  9441. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9442. c = 0;
  9443. loc = strstr(payload, "currentTime");
  9444. memset(sstr ,0, sizeof(sstr) );
  9445. while (loc[3+strlen("currentTime")+c] != '\"')
  9446. {
  9447. sstr[c] = loc[3+strlen("currentTime")+c];
  9448. c++;
  9449. }
  9450. sstr[c] = '\0';
  9451. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9452. // #ifdef SystemLogMessage
  9453. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9454. // #endif
  9455. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9456. tp.tm_isdst = -1;
  9457. //time_t utc = mktime(&tp);
  9458. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9459. memset(timebuf, 0, sizeof timebuf);
  9460. sprintf(timebuf,"date -s '%s'",buf);
  9461. system(timebuf);
  9462. //==============================================
  9463. // RTC sync
  9464. //==============================================
  9465. system("/sbin/hwclock -w --systohc");
  9466. if(FirstHeartBeat == 0)
  9467. {
  9468. FirstHeartBeat = 1;
  9469. }
  9470. HeartBeatWithNOResponse = 0;
  9471. //===============================================
  9472. //Print Out HeartBeat log
  9473. //===============================================
  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] != ',')&&(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] != ',')&&(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. memset(fname, 0, sizeof fname);
  13429. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13430. TxDefaultProfileFileIsNull=TRUE;
  13431. if((access(fname,F_OK))!=-1)
  13432. {
  13433. fptr1 = fopen(fname, "r");
  13434. c = 0;
  13435. c = fgetc(fptr1);
  13436. //DEBUG_INFO("c:%d\n",c);
  13437. rewind(fptr1);
  13438. if(c == EOF)
  13439. {
  13440. DEBUG_INFO("\n End of file reached.");
  13441. TxDefaultProfileFileIsNull=TRUE;
  13442. fclose(fptr1);
  13443. }
  13444. else
  13445. {
  13446. TxDefaultProfileFileIsNull=FALSE;
  13447. while(fscanf(fptr1, "%s", word) != EOF)
  13448. {
  13449. if(strcmp(word, "chargingProfileId") == 0)
  13450. {
  13451. n_chargingProfile = n_chargingProfile + 1;
  13452. }
  13453. }
  13454. rewind(fptr1);
  13455. //search Charging Profile Element
  13456. int i = 0;
  13457. int j = 0;
  13458. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13459. {
  13460. #if 0
  13461. //***********connectorId****************/
  13462. c = 0;
  13463. loc = strstr(sLineWord, "connectorId");
  13464. memset(sstr ,0, sizeof(sstr) );
  13465. while (loc[strlen("connectorId")+2+c] != ',')
  13466. {
  13467. sstr[c] = loc[strlen("connectorId")+2+c];
  13468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13469. c++;
  13470. }
  13471. sstr[c] = '\0';
  13472. tempconnectorIdInt = atoi(sstr);
  13473. #endif
  13474. //***********chargingProfileId**************/
  13475. c = 0;
  13476. loc = strstr(sLineWord, "chargingProfileId");
  13477. //DEBUG_INFO("loc=%s\n",loc);
  13478. memset(sstr ,0, sizeof(sstr) );
  13479. if(loc != NULL)
  13480. {
  13481. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13482. {
  13483. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13485. c++;
  13486. }
  13487. sstr[c] = '\0';
  13488. tempchargingProfileId = atoi(sstr);
  13489. }
  13490. else
  13491. {
  13492. tempchargingProfileId = 0;
  13493. }
  13494. //***********stackLevel**************/
  13495. c = 0;
  13496. loc = strstr(sLineWord, "stackLevel");
  13497. //DEBUG_INFO("loc=%s\n",loc);
  13498. memset(sstr ,0, sizeof(sstr) );
  13499. if(loc != NULL)
  13500. {
  13501. while (loc[2+strlen("stackLevel")+c] != '\"')
  13502. {
  13503. sstr[c] = loc[2+strlen("stackLevel")+c];
  13504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13505. c++;
  13506. }
  13507. sstr[c] = '\0';
  13508. tempstackLevel = atoi(sstr);
  13509. }
  13510. else
  13511. {
  13512. tempstackLevel = 0;
  13513. }
  13514. //***********chargingProfilePurpose **************/
  13515. c = 0;
  13516. loc = strstr(sLineWord, "chargingProfilePurpose");
  13517. //DEBUG_INFO("loc=%s\n",loc);
  13518. memset(sstr ,0, sizeof(sstr) );
  13519. if(loc != NULL)
  13520. {
  13521. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13522. {
  13523. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13524. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13525. c++;
  13526. }
  13527. sstr[c] = '\0';
  13528. strcpy(tempchargingProfilePurposeStr,sstr);
  13529. }
  13530. else
  13531. {
  13532. strcpy(tempchargingProfilePurposeStr,"");
  13533. }
  13534. //***********chargingProfileKind **************/
  13535. c = 0;
  13536. loc = strstr(sLineWord, "chargingProfileKind");
  13537. //DEBUG_INFO("loc=%s\n",loc);
  13538. memset(sstr ,0, sizeof(sstr) );
  13539. if(loc != NULL)
  13540. {
  13541. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13542. {
  13543. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13545. c++;
  13546. }
  13547. sstr[c] = '\0';
  13548. strcpy(tempchargingProfileKindStr,sstr);
  13549. }
  13550. else
  13551. {
  13552. strcpy(tempchargingProfileKindStr,"");
  13553. }
  13554. //***********recurrencyKind **************/
  13555. c = 0;
  13556. loc = strstr(sLineWord, "recurrencyKind");
  13557. //DEBUG_INFO("loc=%s\n",loc);
  13558. memset(sstr ,0, sizeof(sstr) );
  13559. if(loc != NULL)
  13560. {
  13561. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13562. {
  13563. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13564. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13565. c++;
  13566. }
  13567. sstr[c] = '\0';
  13568. strcpy(temprecurrencyKindStr,sstr);
  13569. }
  13570. else
  13571. {
  13572. strcpy(temprecurrencyKindStr,"");
  13573. }
  13574. //***********validFrom**************/
  13575. c = 0;
  13576. loc = strstr(sLineWord, "validFrom");
  13577. if(loc != NULL)
  13578. {
  13579. memset(sstr ,0, sizeof(sstr) );
  13580. while (loc[3+strlen("validFrom")+c] != '\"')
  13581. {
  13582. sstr[c] = loc[3+strlen("validFrom")+c];
  13583. c++;
  13584. }
  13585. sstr[c] = '\0';
  13586. strcpy(tempvalidFromStr,sstr);
  13587. }
  13588. else
  13589. {
  13590. strcpy(tempvalidFromStr,"");
  13591. }
  13592. //***********validTo **************/
  13593. c = 0;
  13594. loc = strstr(sLineWord, "validTo");
  13595. if(loc != NULL)
  13596. {
  13597. memset(sstr ,0, sizeof(sstr) );
  13598. while (loc[3+strlen("validTo")+c] != '\"')
  13599. {
  13600. sstr[c] = loc[3+strlen("validTo")+c];
  13601. c++;
  13602. }
  13603. sstr[c] = '\0';
  13604. strcpy(tempvalidToStr,sstr);
  13605. }
  13606. else
  13607. {
  13608. strcpy(tempvalidToStr,"");
  13609. }
  13610. //***********duration**************/
  13611. c = 0;
  13612. loc = strstr(sLineWord, "duration");
  13613. if(loc != NULL)
  13614. {
  13615. memset(sstr ,0, sizeof(sstr) );
  13616. while (loc[2+strlen("duration")+c] != ',')
  13617. {
  13618. sstr[c] = loc[2+strlen("duration")+c];
  13619. c++;
  13620. }
  13621. sstr[c] = '\0';
  13622. tempdurationInt = atoi(sstr);
  13623. }
  13624. else
  13625. {
  13626. tempdurationInt = 0;
  13627. }
  13628. //**********startSchedule**********/
  13629. c = 0;
  13630. loc = strstr(sLineWord, "startSchedule");
  13631. memset(sstr ,0, sizeof(sstr) );
  13632. while (loc[3+strlen("startSchedule")+c] != '\"')
  13633. {
  13634. sstr[c] = loc[3+strlen("startSchedule")+c];
  13635. c++;
  13636. }
  13637. sstr[c] = '\0';
  13638. strcpy(tempstartScheduleStr, sstr);
  13639. strcpy(TxDefaultProfileScheduleStr, sstr);
  13640. //**********chargingRateUnit**********/
  13641. c = 0;
  13642. loc = strstr(sLineWord, "chargingRateUnit");
  13643. memset(sstr ,0, sizeof(sstr) );
  13644. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13645. {
  13646. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13647. c++;
  13648. }
  13649. sstr[c] = '\0';
  13650. strcpy(tempchargingRateUnitStr, sstr);
  13651. //**********minChargingRate*******/
  13652. c = 0;
  13653. loc = strstr(sLineWord, "minChargingRate");
  13654. if(loc != NULL)
  13655. {
  13656. memset(sstr ,0, sizeof(sstr) );
  13657. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13658. {
  13659. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13660. c++;
  13661. }
  13662. sstr[c] = '\0';
  13663. tempminChargingRateFloat = atof(sstr);
  13664. }
  13665. else
  13666. {
  13667. tempminChargingRateFloat = 0.0;
  13668. }
  13669. //
  13670. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13671. tp.tm_isdst = -1;
  13672. time_t utc = mktime(&tp);
  13673. time_t t = time(NULL);
  13674. diff_t = difftime(t, utc);
  13675. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13676. //parsing strings to words
  13677. i = 0;
  13678. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13679. loc = loc+3+strlen("chargingSchedulePeriod");
  13680. pch = strtok(loc ,"{");
  13681. while (pch != NULL)
  13682. {
  13683. strcpy(SchedulePeriodList[i], pch);
  13684. pch = strtok (NULL, "{");
  13685. i = i + 1;
  13686. }
  13687. n_SchedulePeriods = i;
  13688. for(int i=0;i<n_SchedulePeriods;i++)
  13689. {
  13690. //*************startPeriod****************/
  13691. c = 0;
  13692. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13693. memset(sstr ,0, sizeof(sstr) );
  13694. while (loc[strlen("startPeriod")+2+c] != ',')
  13695. {
  13696. sstr[c] = loc[strlen("startPeriod")+2+c];
  13697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13698. c++;
  13699. }
  13700. sstr[c] = '\0';
  13701. tempStartPeriodInt = atoi(sstr);
  13702. //*************limit****************/
  13703. c = 0;
  13704. loc = strstr(SchedulePeriodList[i], "limit");
  13705. memset(sstr ,0, sizeof(sstr) );
  13706. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  13707. {
  13708. sstr[c] = loc[strlen("limit")+2+c];
  13709. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13710. c++;
  13711. }
  13712. sstr[c] = '\0';
  13713. tempLimitInt = atof(sstr);
  13714. //*************numberPhases****************/
  13715. c = 0;
  13716. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13717. memset(sstr ,0, sizeof(sstr) );
  13718. if(loc != NULL)
  13719. {
  13720. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  13721. {
  13722. sstr[c] = loc[strlen("numberPhases")+2+c];
  13723. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13724. c++;
  13725. }
  13726. sstr[c] = '\0';
  13727. tempNumberPhasesInt = atoi(sstr);
  13728. }
  13729. else
  13730. {
  13731. tempNumberPhasesInt = 0;
  13732. }
  13733. if(j == 0)
  13734. {
  13735. TxDefaultProfile.Duration = tempdurationInt;
  13736. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13737. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13738. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13739. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13740. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13741. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13742. TxDefaultProfile_TEMP.TransactionId = 0;
  13743. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13744. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13745. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13746. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13747. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13748. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13749. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13750. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13751. }
  13752. else
  13753. {
  13754. //other stack level charging Profile
  13755. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13756. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13757. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13758. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13759. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13760. }
  13761. }
  13762. if(MinChargingRate < tempminChargingRateFloat)
  13763. {
  13764. MinChargingRate = tempminChargingRateFloat;
  13765. }
  13766. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13767. if(confirmPeriods < n_SchedulePeriods)
  13768. confirmPeriods = n_SchedulePeriods;
  13769. j = j + 1;
  13770. }
  13771. fclose(fptr1);
  13772. //Stacking Charging Profiles
  13773. for(int l=0; l <(j-1) ;l++)
  13774. {
  13775. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13776. {
  13777. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13778. {
  13779. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13780. {
  13781. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13782. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13783. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13784. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13785. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13786. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13787. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13788. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13789. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13790. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13791. }
  13792. else
  13793. {
  13794. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13795. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13796. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13797. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13798. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13799. }
  13800. }
  13801. }
  13802. }//end of Stacking Charging Profiles
  13803. }// end else
  13804. }// the end of ACCESS TxDefaultProfile
  13805. //****************************TxProfile************************************************/
  13806. memset(fname, 0, sizeof fname);
  13807. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13808. TxProfileIsNull=TRUE;
  13809. if((access(fname,F_OK))!=-1)
  13810. {
  13811. fptr1 = fopen(fname, "r");
  13812. c = 0;
  13813. c = fgetc(fptr1);
  13814. //DEBUG_INFO("c:%d\n",c);
  13815. rewind(fptr1);
  13816. if(c == EOF)
  13817. {
  13818. DEBUG_INFO("\n End of file reached.");
  13819. TxProfileIsNull=TRUE;
  13820. fclose(fptr1);
  13821. }
  13822. else
  13823. {
  13824. TxProfileIsNull=FALSE;
  13825. while(fscanf(fptr1, "%s", word) != EOF)
  13826. {
  13827. if(strcmp(word, "chargingProfileId") == 0)
  13828. {
  13829. n_chargingProfile = n_chargingProfile + 1;
  13830. }
  13831. }
  13832. rewind(fptr1);
  13833. //search Charging Profile Element
  13834. int i= 0;
  13835. int j= 0;
  13836. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13837. #if 0
  13838. /***********connectorId****************/
  13839. c = 0;
  13840. loc = strstr(sLineWord, "connectorId");
  13841. memset(sstr ,0, sizeof(sstr) );
  13842. while (loc[strlen("connectorId")+2+c] != ',')
  13843. {
  13844. sstr[c] = loc[strlen("connectorId")+2+c];
  13845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13846. c++;
  13847. }
  13848. sstr[c] = '\0';
  13849. tempconnectorIdInt = atoi(sstr);
  13850. #endif
  13851. //***********chargingProfileId**************/
  13852. c = 0;
  13853. loc = strstr(sLineWord, "chargingProfileId");
  13854. memset(sstr ,0, sizeof(sstr) );
  13855. if(loc != NULL)
  13856. {
  13857. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13858. {
  13859. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13860. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13861. c++;
  13862. }
  13863. sstr[c] = '\0';
  13864. tempchargingProfileId = atoi(sstr);
  13865. }
  13866. else
  13867. {
  13868. tempchargingProfileId = 0;
  13869. }
  13870. //***********transactionId **************/
  13871. c = 0;
  13872. loc = strstr(sLineWord, "transactionId");
  13873. //DEBUG_INFO("loc=%s\n",loc);
  13874. memset(sstr ,0, sizeof(sstr) );
  13875. if(loc != NULL)
  13876. {
  13877. while (loc[2+strlen("transactionId")+c] != '\"')
  13878. {
  13879. sstr[c] = loc[2+strlen("transactionId")+c];
  13880. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13881. c++;
  13882. }
  13883. sstr[c] = '\0';
  13884. temptransactionId = atoi(sstr);
  13885. }
  13886. else
  13887. {
  13888. temptransactionId = 0;
  13889. }
  13890. //***********stackLevel**************/
  13891. c = 0;
  13892. loc = strstr(sLineWord, "stackLevel");
  13893. //DEBUG_INFO("loc=%s\n",loc);
  13894. memset(sstr ,0, sizeof(sstr) );
  13895. if(loc != NULL)
  13896. {
  13897. while (loc[2+strlen("stackLevel")+c] != '\"')
  13898. {
  13899. sstr[c] = loc[2+strlen("stackLevel")+c];
  13900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13901. c++;
  13902. }
  13903. sstr[c] = '\0';
  13904. tempstackLevel = atoi(sstr);
  13905. }
  13906. else
  13907. {
  13908. tempstackLevel = 0;
  13909. }
  13910. //***********chargingProfilePurpose **************/
  13911. c = 0;
  13912. loc = strstr(sLineWord, "chargingProfilePurpose");
  13913. //DEBUG_INFO("loc=%s\n",loc);
  13914. memset(sstr ,0, sizeof(sstr) );
  13915. if(loc != NULL)
  13916. {
  13917. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13918. {
  13919. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13920. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13921. c++;
  13922. }
  13923. sstr[c] = '\0';
  13924. strcpy(tempchargingProfilePurposeStr,sstr);
  13925. }
  13926. else
  13927. {
  13928. strcpy(tempchargingProfilePurposeStr,"");
  13929. }
  13930. //***********chargingProfileKind **************/
  13931. c = 0;
  13932. loc = strstr(sLineWord, "chargingProfileKind");
  13933. //DEBUG_INFO("loc=%s\n",loc);
  13934. memset(sstr ,0, sizeof(sstr) );
  13935. if(loc != NULL)
  13936. {
  13937. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13938. {
  13939. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13941. c++;
  13942. }
  13943. sstr[c] = '\0';
  13944. strcpy(tempchargingProfileKindStr,sstr);
  13945. }
  13946. else
  13947. {
  13948. strcpy(tempchargingProfileKindStr,"");
  13949. }
  13950. //***********recurrencyKind **************/
  13951. c = 0;
  13952. loc = strstr(sLineWord, "recurrencyKind");
  13953. //DEBUG_INFO("loc=%s\n",loc);
  13954. memset(sstr ,0, sizeof(sstr) );
  13955. if(loc != NULL)
  13956. {
  13957. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13958. {
  13959. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13960. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13961. c++;
  13962. }
  13963. sstr[c] = '\0';
  13964. strcpy(temprecurrencyKindStr,sstr);
  13965. }
  13966. else
  13967. {
  13968. strcpy(temprecurrencyKindStr,"");
  13969. }
  13970. //***********validFrom**************/
  13971. c = 0;
  13972. loc = strstr(sLineWord, "validFrom");
  13973. if(loc != NULL)
  13974. {
  13975. memset(sstr ,0, sizeof(sstr) );
  13976. while (loc[3+strlen("validFrom")+c] != '\"')
  13977. {
  13978. sstr[c] = loc[3+strlen("validFrom")+c];
  13979. c++;
  13980. }
  13981. sstr[c] = '\0';
  13982. strcpy(tempvalidFromStr,sstr);
  13983. }
  13984. else
  13985. {
  13986. strcpy(tempvalidFromStr,"");
  13987. }
  13988. //***********validTo**************/
  13989. c = 0;
  13990. loc = strstr(sLineWord, "validTo");
  13991. if(loc != NULL)
  13992. {
  13993. memset(sstr ,0, sizeof(sstr) );
  13994. while (loc[3+strlen("validTo")+c] != '\"')
  13995. {
  13996. sstr[c] = loc[3+strlen("validTo")+c];
  13997. c++;
  13998. }
  13999. sstr[c] = '\0';
  14000. strcpy(tempvalidToStr,sstr);
  14001. }
  14002. else
  14003. {
  14004. strcpy(tempvalidToStr,"");
  14005. }
  14006. //***********duration**************/
  14007. c = 0;
  14008. loc = strstr(sLineWord, "duration");
  14009. //DEBUG_INFO("loc=%s\n",loc);
  14010. memset(sstr ,0, sizeof(sstr) );
  14011. if(loc != NULL)
  14012. {
  14013. while (loc[2+strlen("duration")+c] != '\"')
  14014. {
  14015. sstr[c] = loc[2+strlen("duration")+c];
  14016. c++;
  14017. }
  14018. sstr[c] = '\0';
  14019. tempdurationInt = atoi(sstr);
  14020. }
  14021. else
  14022. {
  14023. tempdurationInt = 0;
  14024. }
  14025. //**********startSchedule**********/
  14026. c = 0;
  14027. loc = strstr(sLineWord, "startSchedule");
  14028. memset(sstr ,0, sizeof(sstr) );
  14029. while (loc[3+strlen("startSchedule")+c] != '\"')
  14030. {
  14031. sstr[c] = loc[3+strlen("startSchedule")+c];
  14032. c++;
  14033. }
  14034. sstr[c] = '\0';
  14035. strcpy(tempstartScheduleStr, sstr);
  14036. strcpy(TxProfileScheduleStr, sstr);
  14037. //**********chargingRateUnit**********/
  14038. c = 0;
  14039. loc = strstr(sLineWord, "chargingRateUnit");
  14040. memset(sstr ,0, sizeof(sstr) );
  14041. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14042. {
  14043. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14044. c++;
  14045. }
  14046. sstr[c] = '\0';
  14047. strcpy(tempchargingRateUnitStr, sstr);
  14048. //**********minChargingRate*******/
  14049. c = 0;
  14050. loc = strstr(sLineWord, "minChargingRate");
  14051. if(loc != NULL)
  14052. {
  14053. memset(sstr ,0, sizeof(sstr) );
  14054. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14055. {
  14056. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14057. c++;
  14058. }
  14059. sstr[c] = '\0';
  14060. tempminChargingRateFloat = atof(sstr);
  14061. }
  14062. else
  14063. {
  14064. tempminChargingRateFloat = 0.0;
  14065. }
  14066. //
  14067. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14068. tp.tm_isdst = -1;
  14069. time_t utc = mktime(&tp);
  14070. time_t t = time(NULL);
  14071. diff_t = difftime(t, utc);
  14072. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14073. //parsing strings to words
  14074. i = 0;
  14075. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14076. loc = loc+3+strlen("chargingSchedulePeriod");
  14077. pch = strtok(loc ,"{");
  14078. while (pch != NULL)
  14079. {
  14080. strcpy(SchedulePeriodList[i], pch);
  14081. pch = strtok (NULL, "{");
  14082. i = i + 1;
  14083. }
  14084. n_SchedulePeriods = i;
  14085. for(int i=0;i<n_SchedulePeriods;i++)
  14086. {
  14087. //*************startPeriod****************/
  14088. c = 0;
  14089. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14090. memset(sstr ,0, sizeof(sstr) );
  14091. while (loc[strlen("startPeriod")+2+c] != ',')
  14092. {
  14093. sstr[c] = loc[strlen("startPeriod")+2+c];
  14094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14095. c++;
  14096. }
  14097. sstr[c] = '\0';
  14098. tempStartPeriodInt = atoi(sstr);
  14099. //*************limit****************/
  14100. c = 0;
  14101. loc = strstr(SchedulePeriodList[i], "limit");
  14102. memset(sstr ,0, sizeof(sstr) );
  14103. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14104. {
  14105. sstr[c] = loc[strlen("limit")+2+c];
  14106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14107. c++;
  14108. }
  14109. sstr[c] = '\0';
  14110. tempLimitInt = atof(sstr);
  14111. //*************numberPhases****************/
  14112. c = 0;
  14113. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14114. memset(sstr ,0, sizeof(sstr) );
  14115. if(loc != NULL)
  14116. {
  14117. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14118. {
  14119. sstr[c] = loc[strlen("numberPhases")+2+c];
  14120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14121. c++;
  14122. }
  14123. sstr[c] = '\0';
  14124. tempNumberPhasesInt = atoi(sstr);
  14125. }
  14126. else
  14127. {
  14128. tempNumberPhasesInt = 0;
  14129. }
  14130. //TxProfile.Duration = durationInt;
  14131. TxProfile.TotalPeriod = n_SchedulePeriods;
  14132. TxProfile.Period[i].Limit = tempLimitInt;
  14133. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14134. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14135. }
  14136. if(MinChargingRate < tempminChargingRateFloat)
  14137. {
  14138. MinChargingRate = tempminChargingRateFloat;
  14139. }
  14140. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14141. if(confirmPeriods < n_SchedulePeriods)
  14142. confirmPeriods = n_SchedulePeriods;
  14143. if(j == 0)
  14144. {
  14145. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14146. TxProfile_TEMP.StackLevel = tempstackLevel;
  14147. TxProfile_TEMP.TransactionId = 0;
  14148. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14149. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14150. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14151. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14152. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14153. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14154. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14155. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14156. }
  14157. }
  14158. fclose(fptr1);
  14159. }
  14160. }// the end of ACCESS TxProfile
  14161. //-----------------------------------------------CompositeSchedule--------------------------//
  14162. int period=0;
  14163. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14164. {
  14165. //TxProfile
  14166. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14167. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14168. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14169. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14171. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14173. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14174. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14175. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14176. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14177. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14178. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14179. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14180. {
  14181. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14182. {
  14183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14186. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14187. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14188. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14189. period = period + 1;
  14190. }
  14191. else
  14192. {
  14193. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14194. {
  14195. }
  14196. else
  14197. {
  14198. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14199. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14200. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14201. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14202. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14203. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14204. period = period + 1;
  14205. }
  14206. }
  14207. }
  14208. struct tm tp;
  14209. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14210. tp.tm_isdst = -1;
  14211. time_t utc = mktime(&tp);
  14212. time_t t = time(NULL);
  14213. double diff_f = difftime(t, utc);
  14214. int diff_i;// = (int)diff_f;
  14215. int quotient; // = diff_i / 86400;//86400 seconds/day
  14216. if(diff_f >= 0)
  14217. {
  14218. diff_i = (int)diff_f;
  14219. quotient = diff_i / 86400;//86400 seconds/day
  14220. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14221. {
  14222. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14223. {
  14224. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14225. {
  14226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14227. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14228. }
  14229. else
  14230. {
  14231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14232. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14233. }
  14234. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14236. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14237. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14238. period = period + 1;
  14239. }
  14240. }
  14241. }// end of if(diff_f >= 0)
  14242. }
  14243. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14244. {
  14245. //TxDefaultProfile
  14246. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14247. struct tm tp;
  14248. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14249. tp.tm_isdst = -1;
  14250. time_t utc = mktime(&tp);
  14251. time_t t = time(NULL);
  14252. double diff_f = difftime(t, utc);
  14253. int diff_i;// = (int)diff_f;
  14254. int quotient; // = diff_i / 86400;//86400 seconds/day
  14255. int remainder;
  14256. //---- Define StartSchedule----/
  14257. struct tm *gtime;
  14258. time_t now;
  14259. char buf[28];
  14260. //---Read the current system time---/
  14261. time(&now);
  14262. //---Convert the system time to GMT (now UTC)---/
  14263. gtime = gmtime(&now);
  14264. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14265. if(diff_f >= 0)
  14266. {
  14267. diff_i = (int)diff_f;
  14268. quotient = diff_i / 86400;//86400 seconds/day
  14269. remainder = diff_i % 86400;
  14270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14271. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14272. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14275. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14276. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14277. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14278. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14279. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14282. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14283. {
  14284. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14285. {
  14286. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14287. {
  14288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14291. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14292. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14293. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14294. period = period + 1;
  14295. }
  14296. else
  14297. {
  14298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14299. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14300. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14301. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14302. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14303. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14304. period = period + 1;
  14305. }
  14306. }
  14307. }
  14308. } // end of diff_f >= 0
  14309. }
  14310. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14311. {
  14312. //TxDefaultProfile
  14313. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14314. struct tm tp;
  14315. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14316. tp.tm_isdst = -1;
  14317. time_t utc = mktime(&tp);
  14318. time_t t = time(NULL);
  14319. double diff_f = difftime(t, utc);
  14320. int diff_i;// = (int)diff_f;
  14321. int quotient; // = diff_i / 86400;//86400 seconds/day
  14322. int remainder;
  14323. //---- Define StartSchedule----/
  14324. struct tm *gtime;
  14325. time_t now;
  14326. char buf[28];
  14327. //---Read the current system time---/
  14328. time(&now);
  14329. //---Convert the system time to GMT (now UTC)---/
  14330. gtime = gmtime(&now);
  14331. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14332. if(diff_f >= 0)
  14333. {
  14334. diff_i = (int)diff_f;
  14335. quotient = diff_i / 86400;//86400 seconds/day
  14336. remainder = diff_i % 86400;
  14337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14338. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14339. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14340. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14343. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14344. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14345. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14346. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14347. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14350. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14351. {
  14352. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14353. {
  14354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14357. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14358. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14359. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14360. period = period + 1;
  14361. }
  14362. }
  14363. } //end of diff_f >= 0
  14364. }
  14365. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14366. {
  14367. //ChargePointMaxProfile
  14368. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14370. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14371. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14374. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14375. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14376. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14377. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14378. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14379. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14380. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14381. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14382. {
  14383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14386. period = period + 1;
  14387. }
  14388. }
  14389. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14390. {
  14391. //TxProfile Daily
  14392. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14394. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14400. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14401. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14402. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14403. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14404. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14405. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14406. {
  14407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14410. }
  14411. }
  14412. confirmPeriods = period;
  14413. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14414. 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,"
  14415. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14416. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14417. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14418. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14419. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14420. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14421. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14422. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14423. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14424. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14426. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14427. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14428. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14429. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14430. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14431. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14432. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14433. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14439. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14443. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14445. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14446. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14447. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14451. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14454. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14455. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14456. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14457. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14459. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14463. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14464. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14467. }
  14468. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14469. {
  14470. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14471. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14472. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14473. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14474. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14475. }
  14476. int GetWebSocketPingInterval(void)
  14477. {
  14478. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14479. }
  14480. int GetServerSign(void)
  14481. {
  14482. return server_sign;
  14483. }
  14484. void SetServerSign(int value)
  14485. {
  14486. server_sign = value;
  14487. }
  14488. int GetBootNotificationInterval(void)
  14489. {
  14490. return BootNotificationInterval;
  14491. }
  14492. int GetInternetConn(void)
  14493. {
  14494. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14495. }
  14496. void LWS_Send(char * str)
  14497. {
  14498. //=====================================================
  14499. // Check InternetConn 0: disconnected, 1: connected
  14500. //====================================================
  14501. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14502. {
  14503. DEBUG_INFO("\n offline now !!!\n");
  14504. return;
  14505. }
  14506. pthread_mutex_lock(&lock);
  14507. memset(SendBuffer,0,SendBufLen);
  14508. sprintf((char *)SendBuffer, "%s", str);
  14509. pthread_mutex_unlock(&lock);
  14510. lws_callback_on_writable(wsi_client);
  14511. lws_service(context, 10000);//timeout_ms
  14512. }