MessageHandler.c 610 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. //===============================
  100. // Local List Version
  101. //===============================
  102. static int localversion=0;
  103. static char idTagAuthorization[32]={0};
  104. //===============================
  105. // OCPP Path
  106. //===============================
  107. extern char OcppPath[160];
  108. extern char OcppProtocol[10];
  109. extern char OcppHost[50];
  110. extern char OcppTempPath[50];
  111. int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. int authenrequest = FALSE;
  124. int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. int TransactionMessageAttemptsValue = 0;
  152. int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  904. {
  905. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  906. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  907. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  908. }
  909. // Charger PRE_SYS_MODE
  910. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  911. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  912. clientTime.Heartbeat=time((time_t*)NULL);
  913. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  914. {
  915. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  916. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  917. }
  918. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  920. // allocate Configuration memory address
  921. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  922. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  923. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  924. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  926. {
  927. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  928. DEBUG_INFO("DC ...\n");
  929. }
  930. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  931. {
  932. SystemInitial = AC_QUANTITY;
  933. DEBUG_INFO("AC ...\n");
  934. }
  935. //Status / ConnectorPlugIn Setting
  936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  937. {
  938. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  939. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  940. }
  941. for (int index = 0; index < CCS_QUANTITY; index++)
  942. {
  943. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  944. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  945. }
  946. for (int index = 0; index < GB_QUANTITY; index++)
  947. {
  948. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  949. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  950. }
  951. for (int index = 0; index < AC_QUANTITY; index++)
  952. {
  953. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  954. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  955. }
  956. return result;
  957. }
  958. int ProcessShareMemory()
  959. {
  960. if(InitShareMemory() == FAIL)
  961. {
  962. #ifdef SystemLogMessage
  963. DEBUG_ERROR("InitShareMemory NG\n");
  964. #endif
  965. if(ShmStatusCodeData!=NULL)
  966. {
  967. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  968. }
  969. sleep(5);
  970. return FAIL;
  971. }
  972. return PASS;
  973. }
  974. //---------------------------------------------
  975. // new:
  976. // enum SYSTEM_STATUS
  977. // {
  978. // SYS_MODE_BOOTING = 0,
  979. // SYS_MODE_IDLE = 1,
  980. // SYS_MODE_AUTHORIZING = 2,
  981. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  982. // SYS_MODE_REASSIGN = 4,
  983. // SYS_MODE_PREPARING = 5,
  984. // SYS_MODE_PREPARE_FOR_EV = 6,
  985. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  986. // SYS_MODE_CHARGING = 8,
  987. // SYS_MODE_TERMINATING = 9,
  988. // SYS_MODE_COMPLETE = 10,
  989. // SYS_MODE_ALARM = 11,
  990. // SYS_MODE_FAULT = 12,
  991. // SYS_MODE_RESERVATION = 13,
  992. // SYS_MODE_BOOKING = 14,
  993. // SYS_MODE_MAINTAIN = 15,
  994. // SYS_MODE_DEBUG = 16,
  995. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  996. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  997. // SYS_MODE_UPDATE = 19
  998. // };
  999. //
  1000. //
  1001. //-----------------------------------------
  1002. void CheckSystemValue(void)
  1003. {
  1004. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1005. int IdleModeCnt = 0;
  1006. char filenmae[100]={0};
  1007. char str[100]={0};
  1008. //===============================
  1009. // send Heartbeat
  1010. //===============================
  1011. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1012. {
  1013. printf("Heartbeat !!!\n");
  1014. //parameter for test
  1015. sendHeartbeatRequest(0);
  1016. //==============================================
  1017. // Reset Waiting Time
  1018. //==============================================
  1019. clientTime.Heartbeat=time((time_t*)NULL);
  1020. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1021. }
  1022. //==============================================
  1023. // Update firmware request
  1024. //==============================================
  1025. if(isUpdateRequest == TRUE )
  1026. {
  1027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1028. {
  1029. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1030. {
  1031. //check SystemStatus
  1032. /*************************DC*******************************/
  1033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1034. {
  1035. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1036. {
  1037. IdleModeCnt = IdleModeCnt + 1;
  1038. }
  1039. }
  1040. for (int index = 0; index < CCS_QUANTITY; index++)
  1041. {
  1042. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1043. {
  1044. IdleModeCnt = IdleModeCnt + 1;
  1045. }
  1046. }
  1047. for (int index = 0; index < GB_QUANTITY; index++)
  1048. {
  1049. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1050. {
  1051. IdleModeCnt = IdleModeCnt + 1;
  1052. }
  1053. }
  1054. }
  1055. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1056. {
  1057. isUpdateRequest = FALSE;
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. isUpdateRequest = FALSE;
  1073. }
  1074. }
  1075. }
  1076. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1077. {
  1078. //===============================
  1079. // CSU Trigger Reset Conf
  1080. //===============================
  1081. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1082. {
  1083. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1084. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1085. {
  1086. server_sign = FALSE;
  1087. }
  1088. }
  1089. //===============================
  1090. // CSU Trigger Authorize Request
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1093. {
  1094. sendAuthorizeRequest(0);
  1095. authorizeRetryTimes = authorizeRetryTimes + 1;
  1096. if(authorizeRetryTimes < 3)
  1097. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1098. }
  1099. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1100. {
  1101. authorizeRetryTimes = 0;
  1102. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1103. server_sign = FALSE;
  1104. }
  1105. 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))
  1106. {
  1107. sendAuthorizeRequest(0);
  1108. }
  1109. //===============================
  1110. // CSU Trigger Smart Charging Profilw
  1111. //===============================
  1112. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1113. {
  1114. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1115. GetChargingProfileRequest(gun_index);
  1116. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1117. }
  1118. //==============================================
  1119. // Charger start transaction
  1120. //==============================================
  1121. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1122. {
  1123. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1124. sendStartTransactionRequest(gun_index);
  1125. clientTime.StartTransaction = time((time_t*)NULL);
  1126. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1127. }
  1128. //==============================================
  1129. // Charger stop transaction
  1130. //==============================================
  1131. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1132. {
  1133. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1134. sendStopTransactionRequest(gun_index);
  1135. clientTime.StopTransaction = time((time_t*)NULL);
  1136. }
  1137. //==============================================
  1138. // Charger status report
  1139. //==============================================
  1140. /* Check Mode Change */
  1141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1142. {
  1143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1144. {
  1145. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1146. {
  1147. 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]*/ )
  1148. {
  1149. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1150. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1151. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1152. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1153. statusModeChage[gun_index] = TRUE;
  1154. }
  1155. }
  1156. }
  1157. for (int index = 0; index < CCS_QUANTITY; index++)
  1158. {
  1159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1160. {
  1161. 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]*/ )
  1162. {
  1163. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1164. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1165. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1166. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1167. statusModeChage[gun_index] = TRUE;
  1168. }
  1169. }
  1170. }
  1171. for (int index = 0; index < GB_QUANTITY; index++)
  1172. {
  1173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1174. {
  1175. 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]*/ )
  1176. {
  1177. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1178. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1179. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1180. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1181. statusModeChage[gun_index] = TRUE;
  1182. }
  1183. }
  1184. }
  1185. }
  1186. else //AC
  1187. {
  1188. for (int index = 0; index < AC_QUANTITY; index++)
  1189. {
  1190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1191. {
  1192. 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]*/ )
  1193. {
  1194. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1195. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1196. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1198. statusModeChage[gun_index] = TRUE;
  1199. }
  1200. }
  1201. }// END OF FOR
  1202. }// END OF ELSE
  1203. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1204. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1205. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1206. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1207. {
  1208. if(SystemInitial != 0)
  1209. SystemInitial = SystemInitial -1;
  1210. sendStatusNotificationRequest(gun_index);
  1211. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1212. statusModeChage[gun_index] = FALSE;
  1213. }
  1214. //==============================================
  1215. // Meter report
  1216. //==============================================
  1217. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1218. {
  1219. //check Transaction active
  1220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1221. {
  1222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1223. {
  1224. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1225. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1226. {
  1227. meterValueSend[gun_index] =1;
  1228. }
  1229. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1230. {
  1231. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1232. if((access(filenmae,F_OK))!=-1)
  1233. {
  1234. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1235. sprintf(str,"rm -f %s",filenmae);
  1236. system(str);
  1237. }
  1238. }
  1239. }// End for CHAdeMO
  1240. for (int index = 0; index < CCS_QUANTITY; index++)
  1241. {
  1242. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1243. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1244. {
  1245. meterValueSend[gun_index] =1;
  1246. }
  1247. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1248. {
  1249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1250. if((access(filenmae,F_OK))!=-1)
  1251. {
  1252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1253. sprintf(str,"rm -f %s",filenmae);
  1254. system(str);
  1255. }
  1256. }
  1257. } // End for CCS
  1258. for (int index = 0; index < GB_QUANTITY; index++)
  1259. {
  1260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1262. {
  1263. meterValueSend[gun_index] =1;
  1264. }
  1265. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1266. {
  1267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1268. if((access(filenmae,F_OK))!=-1)
  1269. {
  1270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1271. sprintf(str,"rm -f %s",filenmae);
  1272. system(str);
  1273. }
  1274. }
  1275. }// End for GB
  1276. }
  1277. else
  1278. {
  1279. for (int index = 0; index < AC_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }//End for AC
  1297. }//END OF ELSE
  1298. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1299. if(meterValueSend[gun_index] == 1)
  1300. sendMeterValuesRequest(gun_index);
  1301. }
  1302. //==============================================
  1303. // Check Connector reserved
  1304. //==============================================
  1305. //===============================
  1306. // Check if Reserve is expired
  1307. //===============================
  1308. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1309. {
  1310. double diff_t;
  1311. struct tm tp;
  1312. // current time
  1313. time_t t = time(NULL);
  1314. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1315. tp.tm_isdst = -1;
  1316. time_t utc = mktime(&tp);
  1317. diff_t = difftime(utc, t);
  1318. if(diff_t <= 0)
  1319. {
  1320. DEBUG_INFO("reserve expired !!! \n");
  1321. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1322. }
  1323. }//END OF Check if Reserve is expired
  1324. //==========================================
  1325. // csu trigger FirmwareStatusNotificationReq
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1328. {
  1329. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1330. }
  1331. //==========================================
  1332. // csu trigger CancelReservationConf
  1333. //==========================================
  1334. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1335. {
  1336. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1337. }
  1338. //==========================================
  1339. // csu trigger ChangeAvailabilityConf
  1340. //==========================================
  1341. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1342. {
  1343. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1344. }
  1345. //==========================================
  1346. // csu trigger UnlockConnectorConf
  1347. //==========================================
  1348. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1349. {
  1350. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1351. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1352. }
  1353. //==========================================
  1354. // csu trigger ReserveNowConf
  1355. //==========================================
  1356. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1357. {
  1358. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1359. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1360. }
  1361. //==========================================
  1362. // csu trigger DataTransferReq
  1363. //==========================================
  1364. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1365. {
  1366. sendDataTransferRequest(gun_index);
  1367. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1368. }
  1369. }
  1370. }
  1371. //==========================================
  1372. // send request routine
  1373. //==========================================
  1374. int sendAuthorizeRequest(int gun_index)
  1375. {
  1376. mtrace();
  1377. int result = FAIL;
  1378. char message[100]={0};
  1379. char guid[37];
  1380. char tempdata[65]={0};
  1381. DEBUG_INFO("sendAuthorizeRequest \n");
  1382. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1383. //Local Authorize
  1384. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1385. {
  1386. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1389. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1390. result = PASS;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1392. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1393. authorizeRetryTimes = 0;
  1394. return result;
  1395. }
  1396. 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))||
  1397. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1398. {
  1399. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1400. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1401. {
  1402. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1403. {
  1404. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1405. }
  1406. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1407. {
  1408. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1409. }
  1410. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1411. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1412. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1413. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1414. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1415. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1416. authorizeRetryTimes = 0;
  1417. return result;
  1418. }
  1419. else
  1420. {
  1421. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1425. result = PASS;
  1426. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1427. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1428. authorizeRetryTimes = 0;
  1429. return result;
  1430. }
  1431. }
  1432. //initailize struct Authorize
  1433. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1434. //get data from shared memory
  1435. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1436. random_uuid(guid);
  1437. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1438. LWS_Send(message);
  1439. sprintf(tempdata, "Authorize,%d", gun_index);
  1440. if(hashmap_operation(0, guid, tempdata) == 1)
  1441. {
  1442. result = PASS;
  1443. DEBUG_ERROR("Authorize mapItem pass\n");
  1444. }
  1445. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1446. return result;
  1447. }
  1448. int sendBootNotificationRequest(void)
  1449. {
  1450. mtrace();
  1451. int result = FAIL;
  1452. char message[500]={0}, payload[700]={0};
  1453. char guid[37]={0};
  1454. char tempdata[65]={0};
  1455. int IsGunCharging = FALSE;
  1456. //check Transaction active
  1457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1458. {
  1459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1460. {
  1461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1462. {
  1463. IsGunCharging = TRUE;
  1464. }
  1465. }
  1466. for (int index = 0; index < CCS_QUANTITY; index++)
  1467. {
  1468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1469. {
  1470. IsGunCharging = TRUE;
  1471. }
  1472. }
  1473. for (int index = 0; index < GB_QUANTITY; index++)
  1474. {
  1475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1476. {
  1477. IsGunCharging = TRUE;
  1478. }
  1479. }
  1480. }
  1481. else
  1482. {
  1483. for (int index = 0; index < AC_QUANTITY; index++)
  1484. {
  1485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1486. {
  1487. IsGunCharging = TRUE;
  1488. }
  1489. }
  1490. }
  1491. if(IsGunCharging == TRUE)
  1492. {
  1493. server_sign = TRUE;
  1494. return result;
  1495. }
  1496. // Fill BootNotification fields
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1503. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1504. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1505. ShmOCPP16Data->ChargeBoxId
  1506. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1507. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1508. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1509. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1510. ,ShmOCPP16Data->BootNotification.CpIccid
  1511. ,ShmOCPP16Data->BootNotification.CpImsi
  1512. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1513. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1514. random_uuid(guid);
  1515. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1516. LWS_Send(message);
  1517. sprintf(tempdata, "BootNotification,0");
  1518. 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*/)
  1519. {
  1520. result = PASS;
  1521. }
  1522. memset(queuedata, 0, sizeof(queuedata));
  1523. strcpy(queuedata,message);
  1524. return result;
  1525. }
  1526. int sendDataTransferRequest(int gun_index)
  1527. {
  1528. mtrace();
  1529. char message[1000]={0};
  1530. char guid[37]={0};
  1531. char tempdata[65]={0};
  1532. int result = FAIL;
  1533. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1534. random_uuid(guid);
  1535. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1536. MESSAGE_TYPE_CALL,
  1537. guid,
  1538. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1539. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1540. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1541. LWS_Send(message);
  1542. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1543. 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*/)
  1544. {
  1545. result = PASS;
  1546. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1547. }
  1548. return result;
  1549. }
  1550. int sendDiagnosticsStatusNotificationRequest(char *status)
  1551. {
  1552. mtrace();
  1553. int result = FAIL;
  1554. char message[110]={0};
  1555. char guid[37]={0};
  1556. char tempdata[65]={0};
  1557. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1558. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1559. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1560. random_uuid(guid);
  1561. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1562. LWS_Send(message);
  1563. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1564. if(hashmap_operation(0, guid, tempdata) == 1)
  1565. {
  1566. result = PASS;
  1567. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1568. }
  1569. //#ifdef SystemLogMessage
  1570. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1571. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1572. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1573. //#endif
  1574. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1575. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1576. //record status
  1577. if(strcmp(status,"Idle")==0)
  1578. {
  1579. DiagnosticsStatusNotificationStatus = 0;
  1580. }
  1581. else if(strcmp(status,"Uploaded")==0)
  1582. {
  1583. DiagnosticsStatusNotificationStatus = 1;
  1584. }
  1585. else if(strcmp(status,"UploadFailed")==0)
  1586. {
  1587. DiagnosticsStatusNotificationStatus = 2;
  1588. }
  1589. else if(strcmp(status,"Uploading")==0)
  1590. {
  1591. DiagnosticsStatusNotificationStatus = 3;
  1592. }
  1593. return result;
  1594. }
  1595. int sendFirmwareStatusNotificationRequest(char *status)
  1596. {
  1597. mtrace();
  1598. int result = FAIL;
  1599. char message[110]={0};
  1600. char guid[37]={0};
  1601. char tempdata[65]={0};
  1602. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1603. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1604. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1605. random_uuid(guid);
  1606. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1607. LWS_Send(message);
  1608. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1609. 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*/)
  1610. {
  1611. result = PASS;
  1612. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1613. }
  1614. //#ifdef SystemLogMessage
  1615. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1616. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1617. //#endif
  1618. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1619. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1620. //record status
  1621. if(strcmp(status,"Downloaded")==0)
  1622. {
  1623. FirmwareStatusNotificationStatus = 0;
  1624. }
  1625. else if(strcmp(status,"DownloadFailed")==0)
  1626. {
  1627. FirmwareStatusNotificationStatus = 1;
  1628. }
  1629. else if(strcmp(status,"Downloading")==0)
  1630. {
  1631. FirmwareStatusNotificationStatus = 2;
  1632. }
  1633. else if(strcmp(status,"Idle")==0)
  1634. {
  1635. FirmwareStatusNotificationStatus = 3;
  1636. }
  1637. else if(strcmp(status,"InstallationFailed")==0)
  1638. {
  1639. FirmwareStatusNotificationStatus = 4;
  1640. }
  1641. else if(strcmp(status,"Installing")==0)
  1642. {
  1643. FirmwareStatusNotificationStatus = 5;
  1644. }
  1645. else if(strcmp(status,"Installed")==0)
  1646. {
  1647. FirmwareStatusNotificationStatus = 6;
  1648. }
  1649. return result;
  1650. }
  1651. int sendHeartbeatRequest(int gun_index)
  1652. {
  1653. mtrace();
  1654. int result = FAIL;
  1655. char message[80]={0};
  1656. char guid[37]={0};
  1657. char tempdata[65]={0};
  1658. random_uuid(guid);
  1659. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1660. , MESSAGE_TYPE_CALL
  1661. , guid );
  1662. LWS_Send(message);
  1663. sprintf(tempdata, "Heartbeat,%d", 0);
  1664. 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*/)
  1665. {
  1666. result = PASS;
  1667. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1668. }
  1669. return result;
  1670. }
  1671. int sendStartTransactionRequest(int gun_index)
  1672. {
  1673. mtrace();
  1674. int result = FAIL;
  1675. char message[250]={0};
  1676. char guid[37]={0};
  1677. struct timeval tmnow;
  1678. struct tm *tm;
  1679. char buf[28];//, usec_buf[6];
  1680. char tempdata[65]={0};
  1681. DEBUG_INFO("sendStartTransactionRequest...");
  1682. gettimeofday(&tmnow, NULL);
  1683. time_t t;
  1684. t = time(NULL);
  1685. /*UTC time and date*/
  1686. tm = gmtime(&t);
  1687. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1688. #if 0 // remove temporally
  1689. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1690. strcat(buf,".");
  1691. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1692. strcat(buf,usec_buf);
  1693. #endif
  1694. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1695. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1696. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1697. // clear StartTransaction Response
  1698. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1699. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1700. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1701. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1703. {
  1704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1705. {
  1706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1707. {
  1708. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1709. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1710. }
  1711. }
  1712. for (int index = 0; index < CCS_QUANTITY; index++)
  1713. {
  1714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1715. {
  1716. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1717. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1718. }
  1719. }
  1720. for (int index = 0; index < GB_QUANTITY; index++)
  1721. {
  1722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1723. {
  1724. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1725. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. {
  1731. for (int index = 0; index < AC_QUANTITY; index++)
  1732. {
  1733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1734. {
  1735. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1736. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1737. }
  1738. }
  1739. }//END OF ELSE
  1740. random_uuid(guid);
  1741. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1742. , MESSAGE_TYPE_CALL
  1743. , guid
  1744. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1745. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1746. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1747. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1748. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1749. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1750. 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*/)
  1751. {
  1752. result = PASS;
  1753. }
  1754. strcpy(queuedata, message);
  1755. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1756. if(GetTransactionQueueNum() == 1)
  1757. {
  1758. LWS_Send(message);
  1759. }
  1760. #if 0
  1761. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1762. 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*/)
  1763. {
  1764. result = PASS;
  1765. }
  1766. strcpy(queuedata, message);
  1767. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1768. #endif
  1769. //#ifdef SystemLogMessage
  1770. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1771. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1772. //#endif
  1773. return result;
  1774. }
  1775. int sendStatusNotificationRequest(int gun_index)
  1776. {
  1777. mtrace();
  1778. int result = FAIL;
  1779. char message[600]={0};
  1780. char guid[37];
  1781. int currentStatus = 0;
  1782. struct timeval tmnow;
  1783. struct tm *tm;
  1784. char buf[28];//, usec_buf[6];
  1785. char tempdata[65]={0};
  1786. gettimeofday(&tmnow, NULL);
  1787. time_t t;
  1788. t = time(NULL);
  1789. /*UTC time and date*/
  1790. tm = gmtime(&t);
  1791. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1792. #if 0 // remove temporally
  1793. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1794. strcat(buf,".");
  1795. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1796. strcat(buf,usec_buf);
  1797. #endif
  1798. printf("%s",buf);
  1799. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1800. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1801. // it's option
  1802. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1803. /*
  1804. enum _SYSTEM_STATUS
  1805. {
  1806. S_BOOTING = 0,
  1807. S_IDLE, = 1
  1808. S_AUTHORIZING, =2
  1809. S_REASSIGN_CHECK, =3
  1810. S_REASSIGN, =4
  1811. S_PRECHARGE, =5
  1812. S_PREPARING_FOR_EV, =6
  1813. S_PREPARING_FOR_EVSE, =7
  1814. S_CHARGING, =8
  1815. S_TERMINATING, =9
  1816. S_COMPLETE, =10
  1817. S_ALARM, =11
  1818. S_FAULT =12
  1819. }
  1820. */
  1821. //check Transaction active
  1822. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1823. {
  1824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1825. {
  1826. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1827. {
  1828. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1829. {
  1830. currentStatus = 1; //OCPP Status: Preparing
  1831. }
  1832. else
  1833. {
  1834. currentStatus = 0; //OCPP Status: Available
  1835. }
  1836. }
  1837. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1838. {
  1839. currentStatus = 1; //OCPP Status: Preparing
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1842. {
  1843. currentStatus = 2; //OCPP Status: Charging
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1846. {
  1847. currentStatus = 5; //OCPP Status: Finishing
  1848. }
  1849. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1850. {
  1851. currentStatus = 4; //OCPP Status: SuspendedEV
  1852. }
  1853. 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
  1854. {
  1855. currentStatus = 7; //OCPP Status: Unavailable
  1856. }
  1857. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1858. {
  1859. currentStatus = 8; //OCPP Status: Faulted
  1860. }
  1861. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1862. {
  1863. currentStatus = 6; //OCPP Status: Reserved
  1864. }
  1865. }//end of for CHAdeMO_QUANTITY
  1866. for (int index = 0; index < CCS_QUANTITY; index++)
  1867. {
  1868. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1869. {
  1870. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1871. {
  1872. currentStatus = 1; //OCPP Status: Preparing
  1873. }
  1874. else
  1875. {
  1876. currentStatus = 0; //OCPP Status: Available
  1877. }
  1878. }
  1879. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1880. {
  1881. currentStatus = 1; //OCPP Status: Preparing
  1882. }
  1883. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1884. {
  1885. currentStatus = 2; //OCPP Status: Charging
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1888. {
  1889. currentStatus = 5; //OCPP Status: Finishing
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1892. {
  1893. currentStatus = 4; //OCPP Status: SuspendedEV
  1894. }
  1895. 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
  1896. {
  1897. currentStatus = 7; //OCPP Status : Unavailable
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1900. {
  1901. currentStatus = 8; //OCPP Status: Faulted
  1902. }
  1903. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1904. {
  1905. currentStatus = 6; //OCPP Status: Reserved
  1906. }
  1907. }
  1908. for (int index = 0; index < GB_QUANTITY; index++)
  1909. {
  1910. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1911. {
  1912. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1913. {
  1914. currentStatus = 1; //OCPP Status: Preparing
  1915. }
  1916. else
  1917. {
  1918. currentStatus = 0; //OCPP Status: Available
  1919. }
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1922. {
  1923. currentStatus = 1; //OCPP Status: Preparing
  1924. }
  1925. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1926. {
  1927. currentStatus = 2; //OCPP Status: Charging
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1930. {
  1931. currentStatus = 5; //OCPP Status: Finishing
  1932. }
  1933. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1934. {
  1935. currentStatus = 4; //OCPP Status: SuspendedEV
  1936. }
  1937. 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
  1938. {
  1939. currentStatus = 7; //OCPP Status: Unavailable
  1940. }
  1941. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1942. {
  1943. currentStatus = 8; //OCPP Status: Faulted
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1946. {
  1947. currentStatus = 6; //OCPP Status: Reserved
  1948. }
  1949. }
  1950. }
  1951. else
  1952. {
  1953. for (int index = 0; index < AC_QUANTITY; index++)
  1954. {
  1955. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1956. {
  1957. 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))
  1958. {
  1959. currentStatus = 1; //OCPP Status: Preparing
  1960. }
  1961. else
  1962. {
  1963. currentStatus = 0; //OCPP Status: Available
  1964. }
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1967. {
  1968. currentStatus = 1; //OCPP Status: Preparing
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1971. {
  1972. currentStatus = 2; //OCPP Status: Charging
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1975. {
  1976. currentStatus = 5; //OCPP Status: Finishing
  1977. }
  1978. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1979. {
  1980. currentStatus = 4; //OCPP Status: SuspendedEV
  1981. }
  1982. 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
  1983. {
  1984. currentStatus = 7; //OCPP Status: Unavailable
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1987. {
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1991. {
  1992. currentStatus = 6; //OCPP Status: Reserved
  1993. }
  1994. }//end of for AC_QUANTITY
  1995. }//END OF ELSE
  1996. //it's option
  1997. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1998. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1999. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2000. random_uuid(guid);
  2001. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2002. , MESSAGE_TYPE_CALL
  2003. , guid
  2004. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2005. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2006. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2007. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2008. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2009. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2010. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2011. LWS_Send(message);
  2012. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2013. 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*/)
  2014. {
  2015. //DEBUG_ERROR("statusNotification mapitem pass");
  2016. result = PASS;
  2017. }
  2018. return result;
  2019. }
  2020. int sendStopTransactionRequest(int gun_index)
  2021. {
  2022. mtrace();
  2023. int result = FAIL;
  2024. //char message[1500]={0};
  2025. char guid[37]={0};
  2026. char tempdata[65]={0};
  2027. //int idx_sample=0;
  2028. DEBUG_ERROR("sendStopTransactionRequest \n");
  2029. memset(queuedata, 0, sizeof(queuedata));
  2030. //ENERGY_ACTIVE_IMPORT_REGISTER
  2031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2032. {
  2033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2034. {
  2035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2036. {
  2037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2038. }
  2039. }// END OF CHAdeMO_QUANTITY
  2040. for (int index = 0; index < CCS_QUANTITY; index++)
  2041. {
  2042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2043. {
  2044. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2045. }
  2046. }// END OF CCS_QUANTITY
  2047. for (int index = 0; index < GB_QUANTITY; index++)
  2048. {
  2049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2050. {
  2051. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2052. }
  2053. }// END OF GB_QUANTITY
  2054. }
  2055. else
  2056. {
  2057. for (int index = 0; index < AC_QUANTITY; index++)
  2058. {
  2059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2060. {
  2061. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2062. }
  2063. }// END OF AC_QUANTITY
  2064. }//END OF ELSE
  2065. //Stop Transaction Time
  2066. struct timeval tmnow;
  2067. struct tm *tm;
  2068. char buf[28];//, usec_buf[6];
  2069. gettimeofday(&tmnow, NULL);
  2070. time_t t;
  2071. t = time(NULL);
  2072. /*UTC time and date*/
  2073. tm = gmtime(&t);
  2074. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2076. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2077. random_uuid(guid);
  2078. /***********************************transactionData******************************************************/
  2079. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2081. //=================================
  2082. // Transaction_Begin
  2083. //=================================
  2084. // Energy.Active.Export.Interval
  2085. //idx_sample=0;
  2086. 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
  2087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2089. 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*/]);
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2093. }
  2094. else
  2095. {
  2096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2097. }
  2098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2100. //=================================
  2101. // Transaction_End
  2102. //=================================
  2103. //Current.Export
  2104. //idx_sample=1;
  2105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2106. {
  2107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2108. {
  2109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2110. {
  2111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2112. }
  2113. }
  2114. for (int index = 0; index < CCS_QUANTITY; index++)
  2115. {
  2116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2117. {
  2118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2119. }
  2120. }
  2121. for (int index = 0; index < GB_QUANTITY; index++)
  2122. {
  2123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2124. {
  2125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2126. }
  2127. }
  2128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2129. }
  2130. else
  2131. {
  2132. for (int index = 0; index < AC_QUANTITY; index++)
  2133. {
  2134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2135. {
  2136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2137. }
  2138. }
  2139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2140. }// END FOR AC ELSE
  2141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2144. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2147. //Energy.Active.Export.Interval
  2148. //idx_sample=2;
  2149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2150. {
  2151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2152. {
  2153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2154. {
  2155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2156. }
  2157. }
  2158. for (int index = 0; index < CCS_QUANTITY; index++)
  2159. {
  2160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2161. {
  2162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2163. }
  2164. }
  2165. for (int index = 0; index < GB_QUANTITY; index++)
  2166. {
  2167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2168. {
  2169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2170. }
  2171. }
  2172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2173. }
  2174. else
  2175. {
  2176. for (int index = 0; index < AC_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2179. {
  2180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2181. }
  2182. }
  2183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2184. }// END FOR AC ELSE
  2185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2188. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2191. //Power.Active.Export
  2192. //idx_sample=3;
  2193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2194. {
  2195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2196. {
  2197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2198. {
  2199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2200. }
  2201. }
  2202. for (int index = 0; index < CCS_QUANTITY; index++)
  2203. {
  2204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2205. {
  2206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2207. }
  2208. }
  2209. for (int index = 0; index < GB_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2212. {
  2213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2214. }
  2215. }
  2216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2217. }
  2218. else
  2219. {
  2220. for (int index = 0; index < AC_QUANTITY; index++)
  2221. {
  2222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2223. {
  2224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2225. }
  2226. }
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2228. }// END FOR AC ELSE
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2232. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2235. //Voltage
  2236. //idx_sample=4;
  2237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2238. {
  2239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2240. {
  2241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2242. {
  2243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2244. }
  2245. }
  2246. for (int index = 0; index < CCS_QUANTITY; index++)
  2247. {
  2248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2249. {
  2250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2251. }
  2252. }
  2253. for (int index = 0; index < GB_QUANTITY; index++)
  2254. {
  2255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2256. {
  2257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2258. }
  2259. }
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2261. }
  2262. else
  2263. {
  2264. for (int index = 0; index < AC_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2267. {
  2268. 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
  2269. }
  2270. }
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2272. }// END FOR AC ELSE
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2276. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2279. //SoC
  2280. //idx_sample=5;
  2281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2282. {
  2283. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2284. {
  2285. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2286. {
  2287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2288. }
  2289. }
  2290. for (int index = 0; index < CCS_QUANTITY; index++)
  2291. {
  2292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2293. {
  2294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2295. }
  2296. }
  2297. for (int index = 0; index < GB_QUANTITY; index++)
  2298. {
  2299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2300. {
  2301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2302. }
  2303. }
  2304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2310. } // END FOR DC CASE
  2311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2312. {
  2313. 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\"}]}]}]"
  2314. ,MESSAGE_TYPE_CALL
  2315. ,guid
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2321. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2364. );
  2365. }
  2366. else
  2367. {
  2368. 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\"}]}]}]"
  2369. ,MESSAGE_TYPE_CALL
  2370. ,guid
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2376. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2412. );
  2413. }
  2414. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2415. if(hashmap_operation(0, guid, tempdata) == 1)
  2416. {
  2417. result = PASS;
  2418. DEBUG_INFO("StopTransaction mapitem pass\n");
  2419. }
  2420. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2421. if(GetTransactionQueueNum() == 1)
  2422. {
  2423. LWS_Send(queuedata);
  2424. }
  2425. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2426. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2427. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2428. {
  2429. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2430. }
  2431. #if 0
  2432. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2433. if(hashmap_operation(0, guid, tempdata) == 1)
  2434. {
  2435. result = PASS;
  2436. DEBUG_INFO("StopTransaction mapitem pass\n");
  2437. }
  2438. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2439. #endif
  2440. //for test
  2441. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2442. return result;
  2443. }
  2444. int sendMeterValuesRequest(int gun_index)
  2445. {
  2446. mtrace();
  2447. int result = FAIL;
  2448. // char message[1500]={0};
  2449. char guid[37]={0};
  2450. //int idx_sample=0;
  2451. //int length = 0;
  2452. char tempdata[65]={0};
  2453. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2454. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2455. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2456. {
  2457. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2458. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2459. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2460. return result;
  2461. }
  2462. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2463. {
  2464. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2465. }
  2466. memset(queuedata, 0, sizeof(queuedata));
  2467. //set value
  2468. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2469. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2470. random_uuid(guid);
  2471. //UTC Date time
  2472. struct timeval tmnow;
  2473. struct tm *tm;
  2474. char buf[28];//, usec_buf[6];
  2475. gettimeofday(&tmnow, NULL);
  2476. time_t t;
  2477. t = time(NULL);
  2478. /*UTC time and date*/
  2479. tm = gmtime(&t);
  2480. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2482. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2483. //idx_sample=0;
  2484. //********************************(1)Current.Export************************************************/
  2485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2486. {
  2487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2488. {
  2489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2490. {
  2491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2492. }
  2493. }
  2494. for (int index = 0; index < CCS_QUANTITY; index++)
  2495. {
  2496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2497. {
  2498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2499. }
  2500. }
  2501. for (int index = 0; index < GB_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2506. }
  2507. }
  2508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2509. }
  2510. else
  2511. {
  2512. for (int index = 0; index < AC_QUANTITY; index++)
  2513. {
  2514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2515. {
  2516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2517. }
  2518. }
  2519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2520. }// END FOR AC ELSE
  2521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2524. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2527. //idx_sample=1;
  2528. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2530. {
  2531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2532. {
  2533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2534. {
  2535. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2536. }
  2537. }
  2538. for (int index = 0; index < CCS_QUANTITY; index++)
  2539. {
  2540. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2542. {
  2543. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2545. }
  2546. }
  2547. for (int index = 0; index < GB_QUANTITY; index++)
  2548. {
  2549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2550. {
  2551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2552. }
  2553. }
  2554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2555. }
  2556. else
  2557. {
  2558. for (int index = 0; index < AC_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2561. {
  2562. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2563. }
  2564. }
  2565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2566. }//END FOR AC ELSE
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2570. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2573. //idx_sample=2;
  2574. //********************************(4)Power.Active.Export************************************************/
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2578. {
  2579. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2580. {
  2581. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2582. }
  2583. }
  2584. for (int index = 0; index < CCS_QUANTITY; index++)
  2585. {
  2586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2587. {
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2589. }
  2590. }
  2591. for (int index = 0; index < GB_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2594. {
  2595. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2597. }
  2598. }
  2599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2600. }
  2601. else
  2602. {
  2603. for (int index = 0; index < AC_QUANTITY; index++)
  2604. {
  2605. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2606. {
  2607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2608. }
  2609. }
  2610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2611. }// END FOR AC ELSE
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2615. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2618. //idx_sample=3;
  2619. //***********************************************(5)VOLTAGE******************************************************/
  2620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2621. {
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2625. {
  2626. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2627. }
  2628. }
  2629. for (int index = 0; index < CCS_QUANTITY; index++)
  2630. {
  2631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2632. {
  2633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2634. }
  2635. }
  2636. for (int index = 0; index < GB_QUANTITY; index++)
  2637. {
  2638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2639. {
  2640. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2641. }
  2642. }
  2643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2644. }
  2645. else
  2646. {
  2647. for (int index = 0; index < AC_QUANTITY; index++)
  2648. {
  2649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2650. {
  2651. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2652. }
  2653. }
  2654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2655. }//END FOR AC ELSE
  2656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2659. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2663. {
  2664. //idx_sample=4;
  2665. //sampledValue = NULL;
  2666. //***********************************************(6)SOC******************************************************/
  2667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2670. {
  2671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2672. }
  2673. }
  2674. for (int index = 0; index < CCS_QUANTITY; index++)
  2675. {
  2676. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2677. {
  2678. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2679. }
  2680. }
  2681. for (int index = 0; index < GB_QUANTITY; index++)
  2682. {
  2683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2684. {
  2685. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2686. }
  2687. }
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2694. }
  2695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2696. {
  2697. 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\"}]}]}]"
  2698. ,MESSAGE_TYPE_CALL
  2699. ,guid
  2700. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2701. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2702. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2738. );
  2739. }
  2740. else
  2741. {
  2742. 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\"}]}]}]"
  2743. ,MESSAGE_TYPE_CALL
  2744. ,guid
  2745. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2746. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2747. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2776. );
  2777. }
  2778. // Put request guid to hash map
  2779. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2780. 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*/)
  2781. {
  2782. result = PASS;
  2783. DEBUG_INFO("MeterValues mapitem pass\n");
  2784. }
  2785. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2786. if(GetTransactionQueueNum() == 1)
  2787. {
  2788. LWS_Send(queuedata);
  2789. }
  2790. #if 0
  2791. // Put request guid to hash map
  2792. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2793. 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*/)
  2794. {
  2795. result = PASS;
  2796. DEBUG_INFO("MeterValues mapitem pass\n");
  2797. }
  2798. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2799. #endif
  2800. return result;
  2801. }
  2802. //==========================================
  2803. // send confirm routine
  2804. //==========================================
  2805. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2806. {
  2807. mtrace();
  2808. int result = FAIL;
  2809. char message[100]={0};
  2810. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2811. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2812. LWS_Send(message);
  2813. result = TRUE;
  2814. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2815. return result;
  2816. }
  2817. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[100]={0};
  2822. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2824. LWS_Send(message);
  2825. result = TRUE;
  2826. return result;
  2827. }
  2828. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2829. {
  2830. mtrace();
  2831. int result = FAIL;
  2832. char message[100]={0};
  2833. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2834. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2835. LWS_Send(message);
  2836. result = TRUE;
  2837. return result;
  2838. }
  2839. int sendClearCacheConfirmation(char *uuid,char *payload)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[500]={0};
  2844. // int count = 0;
  2845. // int gun_index = 0;
  2846. // char guid[37];
  2847. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2848. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2849. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2850. LWS_Send(message);
  2851. return result;
  2852. }
  2853. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2854. {
  2855. mtrace();
  2856. int result = FAIL;
  2857. char message[500]={0};
  2858. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2859. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2860. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2861. LWS_Send(message);
  2862. return result;
  2863. }
  2864. int sendDataTransferConfirmation(char *uuid,char *payload)
  2865. {
  2866. mtrace();
  2867. char statusStr[20]={0};
  2868. char dataStr[10]={0};
  2869. char sstr[20]={0};
  2870. int c = 0;
  2871. char *loc;
  2872. int result = FAIL;
  2873. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2874. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2875. /**********************status**************************/
  2876. loc = strstr(payload, "status");
  2877. memset(sstr ,0, sizeof(sstr) );
  2878. c = 0;
  2879. while (loc[3+strlen("status")+c] != '\"')
  2880. {
  2881. sstr[c] = loc[3+strlen("status")+c];
  2882. c++;
  2883. }
  2884. sstr[c] = '\0';
  2885. strcpy(statusStr, sstr);
  2886. /**********************data**************************/
  2887. loc = strstr(payload, "data");
  2888. memset(sstr ,0, sizeof(sstr) );
  2889. c = 0;
  2890. while (loc[3+strlen("data")+c] != '\"')
  2891. {
  2892. sstr[c] = loc[3+strlen("data")+c];
  2893. c++;
  2894. }
  2895. sstr[c] = '\0';
  2896. strcpy(dataStr, sstr);
  2897. return result;
  2898. }
  2899. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2900. {
  2901. mtrace();
  2902. int result = FAIL;
  2903. char message[1000]={0};
  2904. double diff_f = 0.0;
  2905. int diff_i = 0;
  2906. int diffSeconds = 0;
  2907. struct tm tp;
  2908. int TimeZero = FALSE;
  2909. int CompositeScheduleIndex = 0;
  2910. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2911. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2912. {
  2913. TimeZero = TRUE;
  2914. }
  2915. else
  2916. {
  2917. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2918. }
  2919. if(TimeZero == FALSE)
  2920. {
  2921. tp.tm_isdst = -1;
  2922. time_t utc = mktime(&tp);
  2923. time_t t = time(NULL);
  2924. diff_f = difftime(t, utc);
  2925. diff_i = (int)diff_f;
  2926. diffSeconds = diff_i % 86400;//86400 seconds/day
  2927. }
  2928. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2929. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2930. #if 0 //remove temporally
  2931. 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}"
  2932. ,MESSAGE_TYPE_CALLRESULT
  2933. ,uuid
  2934. ,payload
  2935. ,connectorIdInt
  2936. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2937. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2938. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2939. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2940. #endif
  2941. if(nPeriod == 0)
  2942. {
  2943. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2944. {
  2945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2946. ,MESSAGE_TYPE_CALLRESULT
  2947. ,uuid
  2948. ,payload
  2949. ,connectorIdInt);
  2950. }
  2951. else
  2952. {
  2953. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2954. ,MESSAGE_TYPE_CALLRESULT
  2955. ,uuid
  2956. ,payload
  2957. ,connectorIdInt
  2958. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2959. }
  2960. }
  2961. else
  2962. {
  2963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2964. ,MESSAGE_TYPE_CALLRESULT
  2965. ,uuid
  2966. ,payload
  2967. ,connectorIdInt
  2968. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2972. int len = nPeriod;
  2973. //Last Period StartPriod is less than diffSeconds
  2974. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2975. {
  2976. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2977. , 0
  2978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2980. }
  2981. else
  2982. {
  2983. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2984. {
  2985. 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)
  2986. {
  2987. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2988. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2989. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2990. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2991. }
  2992. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2993. {
  2994. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2995. , ((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*/))
  2996. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2997. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2998. }
  2999. }
  3000. }
  3001. sprintf(message + strlen(message), "]}}]");
  3002. }
  3003. LWS_Send(message);
  3004. result = TRUE;
  3005. return result;
  3006. }
  3007. int sendGetConfigurationConfirmation(char *uuid)
  3008. {
  3009. mtrace();
  3010. int result = FAIL;
  3011. int MaxKeySupported = 0;
  3012. int sentConfigurationNumber= 0;
  3013. int sentunConfigurationNumber= 0;
  3014. char message[4000]={0};
  3015. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3016. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3017. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3018. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3019. ,MESSAGE_TYPE_CALLRESULT
  3020. ,uuid );
  3021. //configuration key
  3022. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3023. {
  3024. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3025. {
  3026. if (sentConfigurationNumber == 0)
  3027. {
  3028. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3029. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3030. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3031. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3032. }
  3033. else
  3034. {
  3035. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3036. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3037. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3038. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3039. }
  3040. sentConfigurationNumber = sentConfigurationNumber + 1;
  3041. }
  3042. }
  3043. sprintf(message + strlen(message), "]");
  3044. if(UnknownKeynum != 0)
  3045. {
  3046. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3047. //unkown key
  3048. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3049. {
  3050. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3051. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3052. if(sentunConfigurationNumber == 0)
  3053. {
  3054. sprintf(message + strlen(message), "\"%s\""
  3055. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3056. }
  3057. else
  3058. {
  3059. sprintf(message + strlen(message), ",\"%s\""
  3060. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3061. }
  3062. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3063. }
  3064. sprintf(message + strlen(message), "]");
  3065. }
  3066. sprintf(message + strlen(message), "}]");
  3067. LWS_Send(message);
  3068. return result;
  3069. }
  3070. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[400]={0};
  3075. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3076. if(strcmp(payload,"")==0)
  3077. {
  3078. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3079. }
  3080. else
  3081. {
  3082. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3083. }
  3084. LWS_Send(message);
  3085. result = TRUE;
  3086. return result;
  3087. }
  3088. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3089. {
  3090. mtrace();
  3091. int result = FAIL;
  3092. char message[80]={0};
  3093. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3094. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3095. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3096. LWS_Send(message);
  3097. result = TRUE;
  3098. return result;
  3099. }
  3100. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3101. {
  3102. mtrace();
  3103. int result = FAIL;
  3104. char message[80]={0};
  3105. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3106. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3107. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3108. LWS_Send(message);
  3109. result = TRUE;
  3110. return result;
  3111. }
  3112. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3113. {
  3114. mtrace();
  3115. int result = FAIL;
  3116. char message[80]={0};
  3117. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3118. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3120. LWS_Send(message);
  3121. result = TRUE;
  3122. return result;
  3123. }
  3124. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3125. {
  3126. mtrace();
  3127. int result = FAIL;
  3128. char message[80]={0};
  3129. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3130. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3132. LWS_Send(message);
  3133. result = TRUE;
  3134. return result;
  3135. }
  3136. int sendResetConfirmation(char *uuid,char *payload)
  3137. {
  3138. mtrace();
  3139. int result = FAIL;
  3140. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3141. char message[80]={0};
  3142. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3143. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3144. LWS_Send(message);
  3145. result = TRUE;
  3146. return result;
  3147. }
  3148. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3149. {
  3150. mtrace();
  3151. int result = FAIL;
  3152. char message[500]={0};
  3153. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3155. LWS_Send(message);
  3156. result = TRUE;
  3157. return result;
  3158. }
  3159. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3160. {
  3161. mtrace();
  3162. int result = FAIL;
  3163. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3164. char message[80]={0};
  3165. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3166. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3167. LWS_Send(message);
  3168. result = TRUE;
  3169. return result;
  3170. }
  3171. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3172. {
  3173. mtrace();
  3174. int result = FAIL;
  3175. char message[80]={0};
  3176. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3178. LWS_Send(message);
  3179. result = TRUE;
  3180. return result;
  3181. }
  3182. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3183. {
  3184. mtrace();
  3185. int result = FAIL;
  3186. char message[80]={0};
  3187. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3188. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3190. LWS_Send(message);
  3191. result = TRUE;
  3192. return result;
  3193. }
  3194. int sendUpdateFirmwareConfirmation(char *uuid)
  3195. {
  3196. mtrace();
  3197. int result = FAIL;
  3198. char message[60]={0};
  3199. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3200. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3201. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3202. LWS_Send(message);
  3203. result = TRUE;
  3204. return result;
  3205. }
  3206. //==========================================
  3207. // send CallError routine
  3208. //==========================================
  3209. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3210. {
  3211. mtrace();
  3212. //int result = FAIL;
  3213. char message[220]={0};
  3214. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3215. #ifdef SystemLogMessage
  3216. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3217. uniqueId, action, errorCode, errorDescription);
  3218. #endif
  3219. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3220. LWS_Send(message);
  3221. //result = TRUE;
  3222. }
  3223. //==========================================
  3224. // Handle server request routine Start
  3225. //==========================================
  3226. #define GUN_NUM 1
  3227. int handleCancelReservationRequest(char *uuid, char *payload)
  3228. {
  3229. mtrace();
  3230. int result = FAIL;
  3231. int gunNO = 0;
  3232. int reservationIdInt =0;
  3233. char comfirmstr[20];
  3234. int c = 0;
  3235. char *loc;
  3236. char sstr[100]={0};
  3237. DEBUG_INFO("handle CancelReservationRequest\n");
  3238. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3239. c = 0;
  3240. loc = strstr(payload, "reservationId");
  3241. memset(sstr ,0, sizeof(sstr) );
  3242. while (loc[strlen("reservationId")+2+c] != '}')
  3243. {
  3244. sstr[c] = loc[strlen("reservationId")+2+c];
  3245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3246. c++;
  3247. }
  3248. sstr[c] = '\0';
  3249. reservationIdInt = atoi(sstr);
  3250. memset(comfirmstr, 0, sizeof comfirmstr);
  3251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3252. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3253. //check Transaction active
  3254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3255. {
  3256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3257. {
  3258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3259. {
  3260. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3261. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3262. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3264. goto end;
  3265. }
  3266. }
  3267. for (int index = 0; index < CCS_QUANTITY; index++)
  3268. {
  3269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3270. {
  3271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3272. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3273. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3275. goto end;
  3276. }
  3277. }
  3278. for (int index = 0; index < GB_QUANTITY; index++)
  3279. {
  3280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3281. {
  3282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3284. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3285. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3286. goto end;
  3287. }
  3288. }
  3289. }
  3290. else
  3291. {
  3292. for (int index = 0; index < AC_QUANTITY; index++)
  3293. {
  3294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3295. {
  3296. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3297. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3298. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3299. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3300. goto end;
  3301. }
  3302. }
  3303. }// END FOR AC ELSE
  3304. //The reservationId does NOT match the reservationId
  3305. sendCancelReservationConfirmation(uuid, comfirmstr);
  3306. end:
  3307. // Fill in ocpp packet uuid
  3308. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3309. return result;
  3310. }
  3311. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3312. {
  3313. mtrace();
  3314. int result = FAIL;
  3315. int gunIndex = 0;
  3316. char sstr[90]={0};
  3317. char typeStr[16]={0};
  3318. char comfirmstr[20];
  3319. int specificId = FALSE;
  3320. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3321. char *loc;
  3322. //int intervalInt = 0;
  3323. int c = 0;
  3324. /*** connectorId ****/
  3325. c = 0;
  3326. loc = strstr(payload, "connectorId");
  3327. memset(sstr ,0, sizeof(sstr) );
  3328. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3329. {
  3330. sstr[c] = loc[strlen("connectorId")+2+c];
  3331. c++;
  3332. }
  3333. sstr[c] = '\0';
  3334. gunIndex = atoi(sstr);
  3335. /***type ****/
  3336. loc = strstr(payload, "type");
  3337. memset(sstr ,0, sizeof(sstr) );
  3338. c = 0;
  3339. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3340. {
  3341. sstr[c] = loc[3+strlen("type")+c];
  3342. c++;
  3343. }
  3344. sstr[c] = '\0';
  3345. strcpy(typeStr, sstr);
  3346. if(gunIndex != 0)
  3347. {
  3348. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3349. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3350. }
  3351. else
  3352. {
  3353. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3354. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3355. }
  3356. memset(comfirmstr, 0, sizeof comfirmstr);
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3359. {
  3360. specificId = TRUE;
  3361. }
  3362. if(specificId == FALSE)
  3363. goto end;
  3364. if(gunIndex != 0)
  3365. {
  3366. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3367. }
  3368. else
  3369. {
  3370. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3371. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3372. }
  3373. /*
  3374. enum SYSTEM_STATUS
  3375. {
  3376. SYS_MODE_BOOTING = 0,
  3377. SYS_MODE_IDLE = 1,
  3378. SYS_MODE_AUTHORIZING = 2,
  3379. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3380. SYS_MODE_REASSIGN = 4,
  3381. SYS_MODE_PREPARING = 5,
  3382. SYS_MODE_PREPARE_FOR_EV = 6,
  3383. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3384. SYS_MODE_CHARGING = 8,
  3385. SYS_MODE_TERMINATING = 9,
  3386. SYS_MODE_COMPLETE = 10,
  3387. SYS_MODE_ALARM = 11,
  3388. SYS_MODE_FAULT = 12,
  3389. SYS_MODE_RESERVATION = 13,
  3390. SYS_MODE_BOOKING = 14,
  3391. SYS_MODE_MAINTAIN = 15,
  3392. SYS_MODE_DEBUG = 16,
  3393. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3394. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3395. SYS_MODE_UPDATE = 19
  3396. };
  3397. */
  3398. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3399. {
  3400. //check Transaction active
  3401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3402. {
  3403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3404. {
  3405. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3406. {
  3407. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3408. {
  3409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3410. }
  3411. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3412. {
  3413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3414. }
  3415. else
  3416. {
  3417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3418. }
  3419. goto end;
  3420. }
  3421. }//END FOR CHAdeMO_QUANTITY
  3422. for (int index = 0; index < CCS_QUANTITY; index++)
  3423. {
  3424. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3425. {
  3426. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3427. {
  3428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3429. }
  3430. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3431. {
  3432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3433. }
  3434. else
  3435. {
  3436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3437. }
  3438. goto end;
  3439. }
  3440. }//END FOR CCS_QUANTITY
  3441. for (int index = 0; index < GB_QUANTITY; index++)
  3442. {
  3443. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3444. {
  3445. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3448. }
  3449. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3450. {
  3451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3452. }
  3453. else
  3454. {
  3455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3456. }
  3457. goto end;
  3458. }
  3459. }// END FOR GB_QUANTITY
  3460. }
  3461. else
  3462. {
  3463. for (int index = 0; index < AC_QUANTITY; index++)
  3464. {
  3465. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3466. {
  3467. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3468. {
  3469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3470. }
  3471. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3474. }
  3475. else
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3478. }
  3479. goto end;
  3480. }
  3481. }//END FOR AC_QUANTITY
  3482. }// END FOR AC ELSE
  3483. }//END FOR AvailabilityTypeStr[Inoperative]
  3484. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3485. {
  3486. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3487. //check Transaction active
  3488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3489. {
  3490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3491. {
  3492. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. goto end;
  3496. }
  3497. }//END FOR CHAdeMO_QUANTITY
  3498. for (int index = 0; index < CCS_QUANTITY; index++)
  3499. {
  3500. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3501. {
  3502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3503. goto end;
  3504. }
  3505. }//END FOR CCS_QUANTITY
  3506. for (int index = 0; index < GB_QUANTITY; index++)
  3507. {
  3508. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3509. {
  3510. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3512. goto end;
  3513. }
  3514. }// END FOR GB_QUANTITY
  3515. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3516. }
  3517. else
  3518. {
  3519. for (int index = 0; index < AC_QUANTITY; index++)
  3520. {
  3521. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3522. {
  3523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3524. goto end;
  3525. }
  3526. }//END FOR CHAdeMO_QUANTITY
  3527. }//END FOR AC ELSE
  3528. }//END FOR AvailabilityTypeStr[Operative]
  3529. end:
  3530. if(gunIndex != 0)
  3531. {
  3532. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3533. }
  3534. else
  3535. {
  3536. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3537. }
  3538. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3539. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3540. return result;
  3541. }
  3542. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3543. {
  3544. mtrace();
  3545. int result = FAIL;
  3546. char sstr[100]={0};
  3547. char keystr[40]={0};
  3548. char valuestr[100]={0};
  3549. char *loc;
  3550. int c = 0;
  3551. char comfirmstr[20]={0};
  3552. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3553. /***key ****/
  3554. loc = strstr(payload, "key");
  3555. memset(sstr ,0, sizeof(sstr) );
  3556. c = 0;
  3557. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3558. {
  3559. sstr[c] = loc[3+strlen("key")+c];
  3560. c++;
  3561. }
  3562. sstr[c] = '\0';
  3563. strcpy(keystr, sstr);
  3564. //DEBUG_INFO( "keystr=%s\n",keystr);
  3565. /***value ****/
  3566. loc = strstr(payload, "value");
  3567. memset(sstr ,0, sizeof(sstr) );
  3568. c = 0;
  3569. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3570. {
  3571. sstr[c] = loc[3+strlen("value")+c];
  3572. c++;
  3573. }
  3574. sstr[c] = '\0';
  3575. strcpy(valuestr, sstr);
  3576. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3577. if((uuid==NULL) || (payload ==NULL) )
  3578. {
  3579. #ifdef Debug
  3580. DEBUG_INFO("payload is null\n");
  3581. #endif
  3582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3583. }
  3584. else
  3585. {
  3586. int status = setKeyValue(keystr, valuestr);
  3587. switch(status)
  3588. {
  3589. case ConfigurationStatus_Accepted:
  3590. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3591. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3592. StoreConfigurationTable();
  3593. break;
  3594. case ConfigurationStatus_Rejected:
  3595. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3596. break;
  3597. case RebootRequired:
  3598. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3599. StoreConfigurationTable();
  3600. break;
  3601. case NotSupported:
  3602. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3603. break;
  3604. default:
  3605. break;
  3606. }
  3607. }
  3608. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3609. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3610. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3611. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3612. {
  3613. ChageWebSocketPingInterval(atoi(valuestr));
  3614. }
  3615. return result;
  3616. }
  3617. int handleClearCacheRequest(char *uuid, char *payload)
  3618. {
  3619. mtrace();
  3620. int result = FAIL;
  3621. char comfirmstr[20];
  3622. int fd;
  3623. char rmFileCmd[100]={0};
  3624. struct stat stats;
  3625. DEBUG_INFO("handle ClearCacheRequest\n");
  3626. stat("/Storage/OCPP", &stats);
  3627. // Check for directory existence
  3628. if (S_ISDIR(stats.st_mode) == 1)
  3629. {
  3630. //DEBUG_ERROR("\n OCPP directory exist \n");
  3631. }
  3632. else
  3633. {
  3634. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3635. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3636. system(rmFileCmd);
  3637. }
  3638. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3639. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3640. {
  3641. DEBUG_INFO("AuthorizationCache file exist.\n");
  3642. }
  3643. else
  3644. {
  3645. DEBUG_INFO("AuthorizationCache file not exist\n");
  3646. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3647. if(log == NULL)
  3648. {
  3649. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3650. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3651. goto end;
  3652. }
  3653. else
  3654. {
  3655. fclose(log);
  3656. }
  3657. }
  3658. fd = open(AuthorizationCache_JSON,O_RDWR);
  3659. if(fd < 0)
  3660. {
  3661. DEBUG_INFO("open AuthorizationCache file failed\n");
  3662. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3663. }
  3664. else
  3665. {
  3666. DEBUG_INFO("open AuthorizationCache file successful\n");
  3667. //* 清空? 件 */
  3668. ftruncate(fd,0);
  3669. //* ? 新设置? 件? 移??*/
  3670. lseek(fd,0,SEEK_SET);
  3671. close(fd);
  3672. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3673. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3674. }
  3675. end:
  3676. sendClearCacheConfirmation(uuid, comfirmstr);
  3677. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3678. return result;
  3679. }
  3680. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3681. {
  3682. mtrace();
  3683. int result = FAIL;
  3684. int resultRename;
  3685. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3686. char chargingProfilePurposeStr[26]={0};
  3687. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3688. char tempchargingProfilePurposeStr[26]={0};
  3689. char sstr[160]={0};//sstr[200]={ 0 };
  3690. char str[100]={0};
  3691. int c = 0;
  3692. //int i = 0;
  3693. //char * pch;
  3694. char *loc;
  3695. char fname[200]={0};
  3696. char comfirmstr[20]={0};
  3697. char word[1600]={0};
  3698. int clearflag = FALSE;
  3699. int chargingProfileIdIsNULL = FALSE;
  3700. int connectorIsNULL = FALSE;
  3701. int chargingProfilePurposeIsNULL = FALSE;
  3702. int stackLevelIsNULL = FALSE;
  3703. //int GotoEnd = FALSE;
  3704. FILE *fptr1, *fptr2;
  3705. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3706. int n_chargingProfile=0;
  3707. int isEmptyFile = FALSE;
  3708. char sLineWord[1600]={0};
  3709. char chargingProfiles[10][100]={0};
  3710. int ChargeProfileCount = 0;
  3711. char ch;
  3712. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3713. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3714. //***id ****/
  3715. c = 0;
  3716. loc = strstr(payload, "id");
  3717. memset(sstr ,0, sizeof(sstr) );
  3718. if(loc == NULL)
  3719. {
  3720. chargingProfileIdIsNULL = TRUE;
  3721. }
  3722. else
  3723. {
  3724. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3725. {
  3726. sstr[c] = loc[strlen("id")+2+c];
  3727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3728. c++;
  3729. }
  3730. sstr[c] = '\0';
  3731. chargingProfileIdInt = atoi(sstr);
  3732. }
  3733. //***connectorId ****/
  3734. c=0;
  3735. loc = strstr(payload, "connectorId");
  3736. memset(sstr ,0, sizeof(sstr) );
  3737. if(loc == NULL)
  3738. {
  3739. connectorIsNULL = TRUE;
  3740. }
  3741. else
  3742. {
  3743. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3744. {
  3745. sstr[c] = loc[strlen("connectorId")+2+c];
  3746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3747. c++;
  3748. }
  3749. sstr[c] = '\0';
  3750. connectorIdInt = atoi(sstr);
  3751. }
  3752. //***chargingProfilePurpose ****/
  3753. loc = strstr(payload, "chargingProfilePurpose");
  3754. memset(sstr ,0, sizeof(sstr) );
  3755. c = 0;
  3756. if(loc == NULL)
  3757. {
  3758. chargingProfilePurposeIsNULL = TRUE;
  3759. }
  3760. else
  3761. {
  3762. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3763. {
  3764. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3765. c++;
  3766. }
  3767. sstr[c] = '\0';
  3768. strcpy(chargingProfilePurposeStr, sstr);
  3769. }
  3770. //***stackLevel ****/
  3771. c=0;
  3772. loc = strstr(payload, "stackLevel");
  3773. memset(sstr ,0, sizeof(sstr) );
  3774. if(loc == NULL)
  3775. {
  3776. stackLevelIsNULL = TRUE;
  3777. }
  3778. else
  3779. {
  3780. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3781. {
  3782. sstr[c] = loc[strlen("stackLevel")+2+c];
  3783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3784. c++;
  3785. }
  3786. sstr[c] = '\0';
  3787. stackLevelInt = atoi(sstr);
  3788. }
  3789. if(connectorIsNULL == FALSE)
  3790. {
  3791. switch(connectorIdInt)
  3792. {
  3793. case 0:
  3794. if(chargingProfilePurposeIsNULL == TRUE)
  3795. {
  3796. int l = 0;
  3797. strcpy(fname, ChargePointMaxProfile_JSON);
  3798. if((access(fname,F_OK))!=-1)
  3799. {
  3800. strcpy(chargingProfiles[l], fname);
  3801. l = l + 1;
  3802. }
  3803. strcpy(fname, TxDefaultProfile_0_JSON);
  3804. if((access(fname,F_OK))!=-1)
  3805. {
  3806. strcpy(chargingProfiles[l], fname);
  3807. l = l + 1;
  3808. }
  3809. ChargeProfileCount = l;
  3810. }
  3811. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3812. {
  3813. strcpy(fname, ChargePointMaxProfile_JSON);
  3814. if((access(fname,F_OK))!=-1)
  3815. {
  3816. strcpy(chargingProfiles[0], fname);
  3817. ChargeProfileCount = 1;
  3818. }
  3819. }
  3820. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3821. {
  3822. strcpy(fname, TxDefaultProfile_0_JSON);
  3823. if((access(fname,F_OK))!=-1)
  3824. {
  3825. strcpy(chargingProfiles[0], fname);
  3826. ChargeProfileCount = 1;
  3827. }
  3828. }
  3829. break;
  3830. default:
  3831. if(chargingProfilePurposeIsNULL == TRUE)
  3832. {
  3833. int m = 0;
  3834. memset(fname, 0, sizeof fname);
  3835. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3836. if((access(fname,F_OK))!=-1)
  3837. {
  3838. strcpy(chargingProfiles[m], fname);
  3839. m = m + 1;
  3840. }
  3841. memset(fname, 0, sizeof fname);
  3842. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3843. if((access(fname,F_OK))!=-1)
  3844. {
  3845. strcpy(chargingProfiles[m], fname);
  3846. m = m + 1;
  3847. }
  3848. ChargeProfileCount = m;
  3849. }
  3850. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3851. {
  3852. //strcpy(fname, TxDefaultProfile_1_JSON);
  3853. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3854. if((access(fname,F_OK))!=-1)
  3855. {
  3856. strcpy(chargingProfiles[0], fname);
  3857. ChargeProfileCount = 1;
  3858. }
  3859. }
  3860. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3861. {
  3862. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3863. if((access(fname,F_OK))!=-1)
  3864. {
  3865. strcpy(chargingProfiles[0], fname);
  3866. ChargeProfileCount = 1;
  3867. }
  3868. //strcpy(fname, TxProfile_1_JSON);
  3869. }
  3870. //strcpy(fname, ChargePointMaxProfile_JSON );
  3871. break;
  3872. }
  3873. }
  3874. else // Check all Charging Profiles
  3875. {
  3876. int i = 0;
  3877. char fnametemp[200]={0};
  3878. ChargeProfileCount = 0;
  3879. //Check ChargePointMaxProfile.json exit
  3880. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3881. {
  3882. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3883. i = i + 1;
  3884. }
  3885. //Check TxDefaultProfile_0.json exit
  3886. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3887. {
  3888. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3889. i = i + 1;
  3890. }
  3891. //Check TxDefaultProfile_%d.json
  3892. for(int j=1; j <= gunTotalNumber; j++)
  3893. {
  3894. memset(fnametemp, 0, sizeof fnametemp);
  3895. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3896. if((access(fnametemp,F_OK))!=-1)
  3897. {
  3898. strcpy(chargingProfiles[i], fnametemp);
  3899. i = i + 1;
  3900. }
  3901. }
  3902. //Check TxProfile_%d.json
  3903. for(int j=1; j <= gunTotalNumber; j++)
  3904. {
  3905. memset(fnametemp, 0, sizeof fnametemp);
  3906. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3907. if((access(fnametemp,F_OK))!=-1)
  3908. {
  3909. strcpy(chargingProfiles[i], fnametemp);
  3910. i = i + 1;
  3911. }
  3912. }
  3913. ChargeProfileCount = i;
  3914. }// End connectorIsNULL is TRUE
  3915. if(ChargeProfileCount == 0)
  3916. {
  3917. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3918. goto end;
  3919. }
  3920. #if 0
  3921. fptr1 = fopen(fname, "r");
  3922. if (!fptr1)
  3923. {
  3924. //file not exist
  3925. DEBUG_INFO("Unable to open the input file!!\n");
  3926. fptr1 = fopen(fname, "w+");
  3927. }
  3928. fclose(fptr1);
  3929. #endif
  3930. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3931. {
  3932. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3933. goto end;
  3934. }
  3935. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3936. {
  3937. memset(str, 0, sizeof str);
  3938. // clear temp file
  3939. sprintf(str,"rm -f %s",temp);
  3940. system(str);
  3941. for(int k=0; k < ChargeProfileCount; k++)
  3942. {
  3943. memset(str, 0, sizeof str);
  3944. //clear file in C
  3945. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3946. system(str);
  3947. }
  3948. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3949. goto end;
  3950. }
  3951. else if(connectorIsNULL == TRUE)
  3952. {
  3953. for(int k=0; k < ChargeProfileCount; k++)
  3954. {
  3955. fptr1 = fopen(chargingProfiles[k], "r");
  3956. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3957. //Check Charging Profile Count
  3958. while(fscanf(fptr1, "%s", word) != EOF)
  3959. {
  3960. //DEBUG_INFO("word=%s\n",word);
  3961. if(strstr(word, "chargingProfileId")!= NULL)
  3962. {
  3963. //DEBUG_INFO("test chargingProfileId \n");
  3964. n_chargingProfile = n_chargingProfile + 1;
  3965. //DEBUG_INFO("chargingProfileId Found\n");
  3966. }
  3967. }
  3968. rewind(fptr1);
  3969. //search Charging Profile Element
  3970. //int i= 0;
  3971. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3972. {
  3973. //------------------------tempconnectorIdInt------------------------//
  3974. loc = strstr(sLineWord, "connectorId");
  3975. c = 0;
  3976. memset(sstr ,0, sizeof(sstr) );
  3977. while (loc[strlen("connectorId")+2+c] != ',')
  3978. {
  3979. sstr[c] = loc[strlen("connectorId")+2+c];
  3980. c++;
  3981. }
  3982. sstr[c] = '\0';
  3983. tempconnectorIdInt = atoi(sstr);
  3984. printf("file's gun number is %d\n", tempconnectorIdInt);
  3985. //--------------------------chargingProfileId--------------------//
  3986. c = 0;
  3987. loc = strstr(sLineWord, "chargingProfileId");
  3988. memset(sstr ,0, sizeof(sstr) );
  3989. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3990. {
  3991. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3993. c++;
  3994. }
  3995. sstr[c] = '\0';
  3996. tempchargingProfileIdInt = atoi(sstr);
  3997. //stackLevel
  3998. c = 0;
  3999. loc = strstr(sLineWord, "stackLevel");
  4000. memset(sstr ,0, sizeof(sstr) );
  4001. while (loc[strlen("stackLevel")+2+c] != ',')
  4002. {
  4003. sstr[c] = loc[strlen("stackLevel")+2+c];
  4004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4005. c++;
  4006. }
  4007. sstr[c] = '\0';
  4008. tempstackLevelInt = atoi(sstr);
  4009. c = 0;
  4010. loc = strstr(sLineWord, "chargingProfilePurpose");
  4011. memset(sstr ,0, sizeof(sstr) );
  4012. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4013. {
  4014. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4015. c++;
  4016. }
  4017. sstr[c] = '\0';
  4018. strcpy(tempchargingProfilePurposeStr, sstr);
  4019. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4020. {
  4021. //------- not write to fptr2-------//
  4022. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4023. //clearflag = TRUE;
  4024. }
  4025. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4026. {
  4027. //------- not write to fptr2-------//
  4028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4029. }
  4030. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4031. {
  4032. //------- not write to fptr2-------//
  4033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4034. }
  4035. else
  4036. {
  4037. fprintf(fptr2, sLineWord);//writing data into file
  4038. }
  4039. memset(sLineWord, 0, sizeof sLineWord);
  4040. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4041. if(clearflag == TRUE)
  4042. {
  4043. fclose(fptr1);
  4044. fclose(fptr2);
  4045. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4046. system(str);
  4047. // clear temp file
  4048. sprintf(str,"rm -f %s",temp);
  4049. system(str);
  4050. }
  4051. else
  4052. {
  4053. fclose(fptr1);
  4054. fclose(fptr2);
  4055. memset(str, 0, sizeof str);
  4056. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4057. system(str);
  4058. resultRename = rename(temp, chargingProfiles[k]);
  4059. if(resultRename == 0)
  4060. {
  4061. DEBUG_INFO("File ChargingProfile renamed successfully");
  4062. }
  4063. else
  4064. {
  4065. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4066. }
  4067. if(comfirmstr[0]== 0)
  4068. {
  4069. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4070. }
  4071. //Check chargingProfile is empty file
  4072. /*------ Read the file ----------------*/
  4073. fptr1=fopen(chargingProfiles[k],"r");
  4074. ch=fgetc(fptr1);
  4075. rewind(fptr1);
  4076. memset(sLineWord, 0, sizeof sLineWord);
  4077. if(ch!=EOF)
  4078. {
  4079. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4080. {
  4081. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4082. if(sLineWord[0]=='\0')
  4083. {
  4084. isEmptyFile = TRUE;
  4085. break;
  4086. }
  4087. else
  4088. {
  4089. isEmptyFile = FALSE;
  4090. break;
  4091. }
  4092. }
  4093. }
  4094. fclose(fptr1);
  4095. if(isEmptyFile == TRUE)
  4096. {
  4097. memset(str, 0, sizeof str);
  4098. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4099. system(str);
  4100. }
  4101. }
  4102. }// End of while(int k=0; k < ChargePointCount; k++)
  4103. }
  4104. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4105. {
  4106. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4107. for(int k=0; k < ChargeProfileCount; k++)
  4108. {
  4109. fptr1 = fopen(chargingProfiles[k], "r");
  4110. fptr2 = fopen(temp, "w+");
  4111. //Check Charging Profile Count
  4112. while(fscanf(fptr1, "%s", word) != EOF)
  4113. {
  4114. //DEBUG_INFO("word=%s\n",word);
  4115. if(strstr(word, "chargingProfileId")!= NULL)
  4116. {
  4117. //DEBUG_INFO("test chargingProfileId \n");
  4118. n_chargingProfile = n_chargingProfile + 1;
  4119. //DEBUG_INFO("chargingProfileId Found\n");
  4120. }
  4121. }
  4122. rewind(fptr1);
  4123. //search Charging Profile Element
  4124. //int i= 0;
  4125. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4126. {
  4127. //*************************tempconnectorIdInt*********************************/
  4128. loc = strstr(sLineWord, "connectorId");
  4129. c = 0;
  4130. memset(sstr ,0, sizeof(sstr) );
  4131. while (loc[strlen("connectorId")+2+c] != ',')
  4132. {
  4133. sstr[c] = loc[strlen("connectorId")+2+c];
  4134. c++;
  4135. }
  4136. sstr[c] = '\0';
  4137. tempconnectorIdInt = atoi(sstr);
  4138. //chargingProfileId
  4139. c = 0;
  4140. loc = strstr(sLineWord, "chargingProfileId");
  4141. memset(sstr ,0, sizeof(sstr) );
  4142. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4143. {
  4144. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4146. c++;
  4147. }
  4148. sstr[c] = '\0';
  4149. tempchargingProfileIdInt = atoi(sstr);
  4150. //stackLevel
  4151. c = 0;
  4152. loc = strstr(sLineWord, "stackLevel");
  4153. memset(sstr ,0, sizeof(sstr) );
  4154. while (loc[strlen("stackLevel")+2+c] != ',')
  4155. {
  4156. sstr[c] = loc[strlen("stackLevel")+2+c];
  4157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4158. c++;
  4159. }
  4160. sstr[c] = '\0';
  4161. tempstackLevelInt = atoi(sstr);
  4162. c = 0;
  4163. loc = strstr(sLineWord, "chargingProfilePurpose");
  4164. memset(sstr ,0, sizeof(sstr) );
  4165. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4166. {
  4167. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4168. c++;
  4169. }
  4170. sstr[c] = '\0';
  4171. strcpy(tempchargingProfilePurposeStr, sstr);
  4172. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4173. {
  4174. //------- not write to fptr2-------//
  4175. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4176. //clearflag = TRUE;
  4177. }
  4178. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4179. {
  4180. //------- not write to fptr2-------//
  4181. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4182. }
  4183. else if(stackLevelIsNULL == TRUE)
  4184. {
  4185. //Clear Whole File
  4186. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4187. clearflag = TRUE;
  4188. break;
  4189. }
  4190. else
  4191. {
  4192. fprintf(fptr2, sLineWord);//writing data into file
  4193. }
  4194. memset(sLineWord, 0, sizeof sLineWord);
  4195. }
  4196. if(clearflag == TRUE)
  4197. {
  4198. fclose(fptr1);
  4199. fclose(fptr2);
  4200. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4201. system(str);
  4202. // clear temp file
  4203. sprintf(str,"rm -f %s",temp);
  4204. system(str);
  4205. }
  4206. else
  4207. {
  4208. fclose(fptr1);
  4209. fclose(fptr2);
  4210. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4211. system(str);
  4212. resultRename = rename(temp, chargingProfiles[k]);
  4213. if(resultRename == 0)
  4214. {
  4215. DEBUG_INFO("File ChargingProfile renamed successfully");
  4216. }
  4217. else
  4218. {
  4219. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4220. }
  4221. if(comfirmstr[0]== 0)
  4222. {
  4223. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4224. }
  4225. //Check chargingProfile is empty file
  4226. /*------ Read the file ----------------*/
  4227. fptr1=fopen(chargingProfiles[k],"r");
  4228. ch=fgetc(fptr1);
  4229. rewind(fptr1);
  4230. memset(sLineWord, 0, sizeof sLineWord);
  4231. if(ch!=EOF)
  4232. {
  4233. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4234. {
  4235. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4236. if(sLineWord[0]=='\0')
  4237. {
  4238. isEmptyFile = TRUE;
  4239. break;
  4240. }
  4241. else
  4242. {
  4243. isEmptyFile = FALSE;
  4244. break;
  4245. }
  4246. }
  4247. }
  4248. fclose(fptr1);
  4249. if(isEmptyFile == TRUE)
  4250. {
  4251. memset(str, 0, sizeof str);
  4252. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4253. system(str);
  4254. }
  4255. /*------- End of reading ---------------*/
  4256. }
  4257. } // while(int k=0; k < ChargeProfileCount; k++)
  4258. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4259. end:
  4260. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4261. return result;
  4262. }
  4263. int handleDataTransferRequest(char *uuid, char *payload)
  4264. {
  4265. mtrace();
  4266. int result = FAIL;
  4267. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4268. char tempvendorId[255]={0};
  4269. char tempmessageId[50]={0};
  4270. char tempdata[50]={0};
  4271. char sstr[160]={0};//sstr[200]={ 0 };
  4272. char message[80]={0};
  4273. int c = 0;
  4274. char *loc;
  4275. DEBUG_INFO("handle DataTransferRequest\n");
  4276. if((uuid != NULL) && (payload != NULL))
  4277. {
  4278. //===============================
  4279. // vendorId
  4280. //===============================
  4281. c = 0;
  4282. loc = strstr(payload, "vendorId");
  4283. while (loc[strlen("vendorId")+3+c] != '\"')
  4284. {
  4285. sstr[c] = loc[strlen("vendorId")+3+c];
  4286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4287. c++;
  4288. }
  4289. sstr[c] = '\0';
  4290. strcpy(tempvendorId,sstr);
  4291. //===============================
  4292. // messageId
  4293. //===============================
  4294. memset(sstr ,0, sizeof(sstr) );
  4295. c = 0;
  4296. loc = strstr(payload, "messageId");
  4297. while (loc[strlen("messageId")+3+c] != '\"')
  4298. {
  4299. sstr[c] = loc[strlen("messageId")+3+c];
  4300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4301. c++;
  4302. }
  4303. sstr[c] = '\0';
  4304. strcpy(tempmessageId,sstr);
  4305. //===============================
  4306. // data
  4307. //===============================
  4308. memset(sstr ,0, sizeof(sstr) );
  4309. c = 0;
  4310. loc = strstr(payload, "data");
  4311. printf("loc=%s\n",loc);
  4312. while (loc[strlen("data")+3+c] != '\"')
  4313. {
  4314. sstr[c] = loc[strlen("data")+3+c];
  4315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(tempdata,sstr);
  4320. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4321. }
  4322. else
  4323. {
  4324. char guid[37]={0};
  4325. random_uuid(guid);
  4326. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4327. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4328. }
  4329. LWS_Send(message);
  4330. return result;
  4331. }
  4332. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4333. {
  4334. mtrace();
  4335. int result = FAIL;
  4336. int connectorIdInt, durationInt;
  4337. char chargingRateUnitStr[4]={0};
  4338. //int tempconnectorIdInt,
  4339. int tempdurationInt;
  4340. float tempminChargingRateFloat = 0.0;
  4341. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4342. int tempStartPeriodInt=0;
  4343. float tempLimitInt=0.0;//0.1;
  4344. int tempNumberPhasesInt=0;
  4345. char fname[200];
  4346. char comfirmstr[20];
  4347. //float totallimit =0.0;
  4348. float MinChargingRate =0.0;
  4349. //double diff_t;
  4350. //struct tm tp;
  4351. FILE *fptr1;
  4352. int c = 0;
  4353. //int i = 0;
  4354. char * pch;
  4355. char *loc;
  4356. char sstr[200]={ 0 };
  4357. int n_chargingProfile = 0;
  4358. int n_SchedulePeriods = 0;
  4359. char SchedulePeriodList[10][200]={0};
  4360. char sLineWord[1600]={0};
  4361. //int n_periods = 0;
  4362. char word[1000]={0};
  4363. int confirmPeriods = 0;
  4364. struct StructProfile ChargePointMaxProfile;
  4365. struct StructProfile TxDefaultProfile;
  4366. struct StructProfile TxProfile;
  4367. struct StructProfile TxDefaultProfiletemp[2]={0};
  4368. int TxDefaultProfileFileIsNull=FALSE;
  4369. int ChargePointMaxProfileIsNull=FALSE;
  4370. int TxProfileIsNull=FALSE;
  4371. int CompositeSceduleIndex = 0;
  4372. char ChargePointMaxProfileScheduleStr[30]={0};
  4373. char TxDefaultProfileScheduleStr[30]={0};
  4374. char TxProfileScheduleStr[30]={0};
  4375. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4376. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4377. memset(&TxProfile,0,sizeof(struct StructProfile));
  4378. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4379. c=0;
  4380. loc = strstr(payload, "connectorId");
  4381. memset(sstr ,0, sizeof(sstr) );
  4382. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4383. {
  4384. sstr[c] = loc[strlen("connectorId")+2+c];
  4385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4386. c++;
  4387. }
  4388. sstr[c] = '\0';
  4389. connectorIdInt = atoi(sstr);
  4390. c=0;
  4391. loc = strstr(payload, "duration");
  4392. memset(sstr ,0, sizeof(sstr) );
  4393. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4394. {
  4395. sstr[c] = loc[strlen("duration")+2+c];
  4396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4397. c++;
  4398. }
  4399. sstr[c] = '\0';
  4400. durationInt = atoi(sstr);
  4401. c = 0;
  4402. loc = strstr(payload, "chargingRateUnit");
  4403. memset(sstr ,0, sizeof(sstr) );
  4404. if(loc == NULL)
  4405. {
  4406. }
  4407. else
  4408. {
  4409. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4410. {
  4411. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. strcpy(chargingRateUnitStr, sstr);
  4416. }
  4417. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4418. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4419. if(connectorIdInt==0) // connectorId is 0
  4420. {
  4421. //******************************ChargePointMaxProfile*****************************************************/
  4422. strcpy(fname, ChargePointMaxProfile_JSON );
  4423. char word[30]={0};
  4424. char sLineWord[1060]={0};
  4425. int n_chargingProfile=0;
  4426. ChargePointMaxProfileIsNull=TRUE;
  4427. if((access(fname,F_OK))!=-1)
  4428. {
  4429. fptr1 = fopen(fname, "r");
  4430. int c;
  4431. c = fgetc(fptr1);
  4432. //DEBUG_INFO("c:%d\n",c);
  4433. rewind(fptr1);
  4434. if(c == EOF)
  4435. {
  4436. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4437. ChargePointMaxProfileIsNull=TRUE;
  4438. fclose(fptr1);
  4439. }
  4440. else
  4441. {
  4442. ChargePointMaxProfileIsNull=FALSE;
  4443. while(fscanf(fptr1, "%s", word) != EOF)
  4444. {
  4445. if(strcmp(word, "chargingProfileId") == 0)
  4446. {
  4447. n_chargingProfile = n_chargingProfile + 1;
  4448. printf("Found\n");
  4449. }
  4450. }
  4451. rewind(fptr1);
  4452. //search Charging Profile Element
  4453. int i= 0;
  4454. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4455. #if 0
  4456. /***********connectorId****************/
  4457. c = 0;
  4458. loc = strstr(sLineWord, "connectorId");
  4459. // printf("loc=%s\n",loc);
  4460. memset(sstr ,0, sizeof(sstr) );
  4461. while (loc[strlen("connectorId")+2+c] != ',')
  4462. {
  4463. sstr[c] = loc[strlen("connectorId")+2+c];
  4464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4465. c++;
  4466. }
  4467. sstr[c] = '\0';
  4468. tempconnectorIdInt = atoi(sstr);
  4469. #endif
  4470. //***********validFrom**************/
  4471. c = 0;
  4472. loc = strstr(sLineWord, "validFrom");
  4473. //DEBUG_INFO("loc=%s\n",loc);
  4474. memset(sstr ,0, sizeof(sstr) );
  4475. if(loc != NULL)
  4476. {
  4477. while (loc[3+strlen("validFrom")+c] != '\"')
  4478. {
  4479. sstr[c] = loc[3+strlen("validFrom")+c];
  4480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4481. c++;
  4482. }
  4483. sstr[c] = '\0';
  4484. DEBUG_INFO("validFrom=%s\n",sstr);
  4485. strcpy(tempvalidFromStr,sstr);
  4486. }
  4487. else
  4488. {
  4489. strcpy(tempvalidFromStr,"");
  4490. }
  4491. //**********startSchedule**********/
  4492. c = 0;
  4493. loc = strstr(sLineWord, "startSchedule");
  4494. //DEBUG_INFO("loc=%s\n",loc);
  4495. memset(sstr ,0, sizeof(sstr) );
  4496. while (loc[3+strlen("startSchedule")+c] != '\"')
  4497. {
  4498. sstr[c] = loc[3+strlen("startSchedule")+c];
  4499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4500. c++;
  4501. }
  4502. sstr[c] = '\0';
  4503. strcpy(tempstartScheduleStr, sstr);
  4504. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4505. //**********chargingRateUnit**********/
  4506. c = 0;
  4507. loc = strstr(sLineWord, "chargingRateUnit");
  4508. memset(sstr ,0, sizeof(sstr) );
  4509. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4510. {
  4511. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4512. c++;
  4513. }
  4514. sstr[c] = '\0';
  4515. strcpy(tempchargingRateUnitStr, sstr);
  4516. //**********minChargingRate*******/
  4517. c = 0;
  4518. loc = strstr(sLineWord, "minChargingRate");
  4519. //printf("loc=%s\n",loc);
  4520. if(loc != NULL)
  4521. {
  4522. memset(sstr ,0, sizeof(sstr) );
  4523. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4524. {
  4525. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4527. c++;
  4528. }
  4529. sstr[c] = '\0';
  4530. tempminChargingRateFloat = atof(sstr);
  4531. }
  4532. else
  4533. {
  4534. tempminChargingRateFloat = 0.0;
  4535. }
  4536. //
  4537. #if 0
  4538. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4539. tp.tm_isdst = -1;
  4540. time_t utc = mktime(&tp);
  4541. // current time
  4542. time_t t = time(NULL);
  4543. #endif
  4544. //diff_t = difftime(t, utc);
  4545. //parsing strings to words
  4546. i = 0;
  4547. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4548. loc = loc+3+strlen("chargingSchedulePeriod");
  4549. pch = strtok(loc ,"{");
  4550. while (pch != NULL)
  4551. {
  4552. strcpy(SchedulePeriodList[i], pch);
  4553. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4554. //printf ("%s\n",pch);
  4555. pch = strtok (NULL, "{");
  4556. i = i + 1;
  4557. }
  4558. n_SchedulePeriods = i;
  4559. for(int i=0;i<n_SchedulePeriods;i++)
  4560. {
  4561. //*************startPeriod****************/
  4562. c = 0;
  4563. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4564. memset(sstr ,0, sizeof(sstr) );
  4565. while (loc[strlen("startPeriod")+2+c] != ',')
  4566. {
  4567. sstr[c] = loc[strlen("startPeriod")+2+c];
  4568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. tempStartPeriodInt = atoi(sstr);
  4573. //*************limit****************/
  4574. c = 0;
  4575. loc = strstr(SchedulePeriodList[i], "limit");
  4576. memset(sstr ,0, sizeof(sstr) );
  4577. while (loc[strlen("limit")+2+c] != ',')
  4578. {
  4579. sstr[c] = loc[strlen("limit")+2+c];
  4580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4581. c++;
  4582. }
  4583. sstr[c] = '\0';
  4584. tempLimitInt = atof(sstr);
  4585. //*************numberPhases****************/
  4586. c = 0;
  4587. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4588. memset(sstr ,0, sizeof(sstr) );
  4589. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4590. {
  4591. sstr[c] = loc[strlen("numberPhases")+2+c];
  4592. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4593. c++;
  4594. }
  4595. sstr[c] = '\0';
  4596. tempNumberPhasesInt = atoi(sstr);
  4597. ChargePointMaxProfile.Duration = durationInt;
  4598. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4599. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4600. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4601. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4602. }
  4603. if(MinChargingRate < tempminChargingRateFloat)
  4604. MinChargingRate = tempminChargingRateFloat;
  4605. }
  4606. }// End of file ChargingProfile
  4607. } //THE END OF ACCESS ChargePointMaxProfile
  4608. //******************************TxDefaultProfile***********************************************/
  4609. strcpy(fname, TxDefaultProfile_0_JSON);
  4610. memset(word, 0, 30);
  4611. memset(sLineWord, 0, 1060);
  4612. //char word[30]={0};
  4613. //char sLineWord[1060]={0};
  4614. n_chargingProfile=0;
  4615. TxDefaultProfileFileIsNull=TRUE;
  4616. if((access(fname,F_OK))!=-1)
  4617. {
  4618. fptr1 = fopen(fname, "r");
  4619. c = 0;
  4620. c = fgetc(fptr1);
  4621. //DEBUG_INFO("c:%d\n",c);
  4622. rewind(fptr1);
  4623. if(c == EOF)
  4624. {
  4625. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4626. TxDefaultProfileFileIsNull=TRUE;
  4627. fclose(fptr1);
  4628. }
  4629. else
  4630. {
  4631. TxDefaultProfileFileIsNull=FALSE;
  4632. while(fscanf(fptr1, "%s", word) != EOF)
  4633. {
  4634. if(strcmp(word, "chargingProfileId") == 0)
  4635. {
  4636. n_chargingProfile = n_chargingProfile + 1;
  4637. printf("Found\n");
  4638. }
  4639. }
  4640. rewind(fptr1);
  4641. //search Charging Profile Element
  4642. int i= 0;
  4643. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4644. #if 0
  4645. /***********connectorId****************/
  4646. c = 0;
  4647. loc = strstr(sLineWord, "connectorId");
  4648. // printf("loc=%s\n",loc);
  4649. memset(sstr ,0, sizeof(sstr) );
  4650. while (loc[strlen("connectorId")+2+c] != ',')
  4651. {
  4652. sstr[c] = loc[strlen("connectorId")+2+c];
  4653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4654. c++;
  4655. }
  4656. sstr[c] = '\0';
  4657. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4658. tempconnectorIdInt = atoi(sstr);
  4659. #endif
  4660. //***********validFrom**************/
  4661. c = 0;
  4662. loc = strstr(sLineWord, "validFrom");
  4663. //DEBUG_INFO("loc=%s\n",loc);
  4664. memset(sstr ,0, sizeof(sstr) );
  4665. if(loc != NULL)
  4666. {
  4667. while (loc[3+strlen("validFrom")+c] != '\"')
  4668. {
  4669. sstr[c] = loc[3+strlen("validFrom")+c];
  4670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. DEBUG_INFO("validFrom=%s\n",sstr);
  4675. strcpy(tempvalidFromStr,sstr);
  4676. }
  4677. else
  4678. {
  4679. strcpy(tempvalidFromStr,"");
  4680. }
  4681. //**********startSchedule**********/
  4682. c = 0;
  4683. loc = strstr(sLineWord, "startSchedule");
  4684. //DEBUG_INFO("loc=%s\n",loc);
  4685. memset(sstr ,0, sizeof(sstr) );
  4686. while (loc[3+strlen("startSchedule")+c] != '\"')
  4687. {
  4688. sstr[c] = loc[3+strlen("startSchedule")+c];
  4689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(tempstartScheduleStr, sstr);
  4694. strcpy(TxDefaultProfileScheduleStr, sstr);
  4695. //**********chargingRateUnit**********/
  4696. c = 0;
  4697. loc = strstr(sLineWord, "chargingRateUnit");
  4698. memset(sstr ,0, sizeof(sstr) );
  4699. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4700. {
  4701. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4702. c++;
  4703. }
  4704. sstr[c] = '\0';
  4705. strcpy(tempchargingRateUnitStr, sstr);
  4706. //**********minChargingRate*******/
  4707. c = 0;
  4708. loc = strstr(sLineWord, "minChargingRate");
  4709. //printf("loc=%s\n",loc);
  4710. if(loc != NULL)
  4711. {
  4712. memset(sstr ,0, sizeof(sstr) );
  4713. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4714. {
  4715. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4716. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4717. c++;
  4718. }
  4719. sstr[c] = '\0';
  4720. tempminChargingRateFloat = atof(sstr);
  4721. }
  4722. else
  4723. {
  4724. tempminChargingRateFloat = 0.0;
  4725. }
  4726. #if 0
  4727. //
  4728. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4729. tp.tm_isdst = -1;
  4730. time_t utc = mktime(&tp);
  4731. // current time
  4732. time_t t = time(NULL);
  4733. //diff_t = difftime(t, utc);
  4734. #endif
  4735. //parsing strings to words
  4736. i = 0;
  4737. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4738. loc = loc+3+strlen("chargingSchedulePeriod");
  4739. pch = strtok(loc ,"{");
  4740. while (pch != NULL)
  4741. {
  4742. strcpy(SchedulePeriodList[i], pch);
  4743. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4744. //printf ("%s\n",pch);
  4745. pch = strtok (NULL, "{");
  4746. i = i + 1;
  4747. }
  4748. n_SchedulePeriods = i;
  4749. for(int i=0;i<n_SchedulePeriods;i++)
  4750. {
  4751. //*************startPeriod****************/
  4752. c = 0;
  4753. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4754. memset(sstr ,0, sizeof(sstr) );
  4755. while (loc[strlen("startPeriod")+2+c] != ',')
  4756. {
  4757. sstr[c] = loc[strlen("startPeriod")+2+c];
  4758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempStartPeriodInt = atoi(sstr);
  4763. //*************limit****************/
  4764. c = 0;
  4765. loc = strstr(SchedulePeriodList[i], "limit");
  4766. memset(sstr ,0, sizeof(sstr) );
  4767. while (loc[strlen("limit")+2+c] != ',')
  4768. {
  4769. sstr[c] = loc[strlen("limit")+2+c];
  4770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4771. c++;
  4772. }
  4773. sstr[c] = '\0';
  4774. tempLimitInt = atof(sstr);
  4775. //*************numberPhases****************/
  4776. c = 0;
  4777. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4778. memset(sstr ,0, sizeof(sstr) );
  4779. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4780. {
  4781. sstr[c] = loc[strlen("numberPhases")+2+c];
  4782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4783. c++;
  4784. }
  4785. sstr[c] = '\0';
  4786. tempNumberPhasesInt = atoi(sstr);
  4787. TxDefaultProfile.Duration = durationInt;
  4788. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4789. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4790. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4791. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4792. }
  4793. if(MinChargingRate < tempminChargingRateFloat)
  4794. MinChargingRate = tempminChargingRateFloat;
  4795. }
  4796. }
  4797. }// the end of ACCESS TxDefaultProfile
  4798. //--------------------- Composite Schedule-----------------------------//
  4799. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4800. {
  4801. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4802. struct tm tp;
  4803. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4804. tp.tm_isdst = -1;
  4805. time_t utc = mktime(&tp);
  4806. time_t t = time(NULL);
  4807. double diff_f = difftime(t, utc);
  4808. int diff_i; //= (int)diff_f;
  4809. int quotient; //= diff_i / 86400;//86400 seconds/day
  4810. int period = 0;
  4811. if(diff_f >= 0)
  4812. {
  4813. diff_i = (int)diff_f;
  4814. quotient = diff_i / 86400;
  4815. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4816. {
  4817. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4818. {
  4819. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4820. {
  4821. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4822. }
  4823. else
  4824. {
  4825. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4826. }
  4827. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4828. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4829. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4830. period = period + 1;
  4831. }
  4832. }
  4833. }
  4834. confirmPeriods = period;
  4835. }
  4836. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4837. {
  4838. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4839. struct tm tp;
  4840. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4841. tp.tm_isdst = -1;
  4842. time_t utc = mktime(&tp);
  4843. time_t t = time(NULL);
  4844. double diff_f = difftime(t, utc);
  4845. int diff_i; // = (int)diff_f;
  4846. int quotient; // = diff_i / 86400;//86400 seconds/day
  4847. int period = 0;
  4848. if(diff_f >= 0)
  4849. {
  4850. diff_i = (int)diff_f;
  4851. quotient = diff_i / 86400;//86400 seconds/day
  4852. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4853. {
  4854. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4855. {
  4856. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4857. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4858. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4859. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4860. period = period + 1;
  4861. }
  4862. }
  4863. }
  4864. confirmPeriods = period;
  4865. }
  4866. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4867. {
  4868. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4869. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4870. {
  4871. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4872. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4873. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4874. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4875. }
  4876. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4877. }
  4878. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4879. {
  4880. confirmPeriods = 0;
  4881. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4882. goto end;
  4883. }
  4884. //* Define temporary variables */
  4885. struct tm *gtime;
  4886. time_t now;
  4887. char buf[28];
  4888. /* Read the current system time */
  4889. time(&now);
  4890. /* Convert the system time to GMT (now UTC) */
  4891. gtime = gmtime(&now);
  4892. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4893. // make .conf
  4894. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4895. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4896. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4897. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4898. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4899. }
  4900. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4901. {
  4902. //*****************************ChargePointMaxProfile******************************************/
  4903. strcpy(fname, ChargePointMaxProfile_JSON);
  4904. ChargePointMaxProfileIsNull=TRUE;
  4905. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4906. {
  4907. fptr1 = fopen(fname, "r");
  4908. int c;
  4909. c = fgetc(fptr1);
  4910. //DEBUG_INFO("c:%d\n",c);
  4911. rewind(fptr1);
  4912. if(c == EOF)
  4913. {
  4914. DEBUG_INFO("\n End of file reached.");
  4915. ChargePointMaxProfileIsNull=TRUE;
  4916. fclose(fptr1);
  4917. }
  4918. else
  4919. {
  4920. ChargePointMaxProfileIsNull=FALSE;
  4921. while(fscanf(fptr1, "%s", word) != EOF)
  4922. {
  4923. if(strcmp(word, "chargingProfileId") == 0)
  4924. {
  4925. n_chargingProfile = n_chargingProfile + 1;
  4926. }
  4927. }
  4928. rewind(fptr1);
  4929. //search Charging Profile Element
  4930. int i = 0;
  4931. int j = 0;
  4932. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4933. #if 0
  4934. /***********connectorId****************/
  4935. c = 0;
  4936. loc = strstr(sLineWord, "connectorId");
  4937. memset(sstr ,0, sizeof(sstr) );
  4938. while (loc[strlen("connectorId")+2+c] != ',')
  4939. {
  4940. sstr[c] = loc[strlen("connectorId")+2+c];
  4941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4942. c++;
  4943. }
  4944. sstr[c] = '\0';
  4945. tempconnectorIdInt = atoi(sstr);
  4946. #endif
  4947. //***********validFrom**************/
  4948. c = 0;
  4949. loc = strstr(sLineWord, "validFrom");
  4950. if(loc != NULL)
  4951. {
  4952. memset(sstr ,0, sizeof(sstr) );
  4953. while (loc[3+strlen("validFrom")+c] != '\"')
  4954. {
  4955. sstr[c] = loc[3+strlen("validFrom")+c];
  4956. c++;
  4957. }
  4958. sstr[c] = '\0';
  4959. strcpy(tempvalidFromStr,sstr);
  4960. }
  4961. else
  4962. {
  4963. strcpy(tempvalidFromStr,"");
  4964. }
  4965. //***********validFrom**************/
  4966. c = 0;
  4967. loc = strstr(sLineWord, "duration");
  4968. if(loc != NULL)
  4969. {
  4970. memset(sstr ,0, sizeof(sstr) );
  4971. while (loc[2+strlen("duration")+c] != ',')
  4972. {
  4973. sstr[c] = loc[2+strlen("duration")+c];
  4974. c++;
  4975. }
  4976. sstr[c] = '\0';
  4977. tempdurationInt = atoi(sstr);
  4978. }
  4979. else
  4980. {
  4981. tempdurationInt = 0;
  4982. }
  4983. //**********startSchedule**********/
  4984. c = 0;
  4985. loc = strstr(sLineWord, "startSchedule");
  4986. memset(sstr ,0, sizeof(sstr) );
  4987. while (loc[3+strlen("startSchedule")+c] != '\"')
  4988. {
  4989. sstr[c] = loc[3+strlen("startSchedule")+c];
  4990. c++;
  4991. }
  4992. sstr[c] = '\0';
  4993. strcpy(tempstartScheduleStr, sstr);
  4994. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4995. //**********chargingRateUnit**********/
  4996. c = 0;
  4997. loc = strstr(sLineWord, "chargingRateUnit");
  4998. memset(sstr ,0, sizeof(sstr) );
  4999. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5000. {
  5001. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5002. c++;
  5003. }
  5004. sstr[c] = '\0';
  5005. strcpy(tempchargingRateUnitStr, sstr);
  5006. //**********minChargingRate*******/
  5007. c = 0;
  5008. loc = strstr(sLineWord, "minChargingRate");
  5009. if(loc != NULL)
  5010. {
  5011. memset(sstr ,0, sizeof(sstr) );
  5012. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5013. {
  5014. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5015. c++;
  5016. }
  5017. sstr[c] = '\0';
  5018. tempminChargingRateFloat = atof(sstr);
  5019. }
  5020. else
  5021. {
  5022. tempminChargingRateFloat = 0.0;
  5023. }
  5024. #if 0
  5025. //
  5026. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5027. tp.tm_isdst = -1;
  5028. time_t utc = mktime(&tp);
  5029. time_t t = time(NULL);
  5030. //diff_t = difftime(t, utc);
  5031. #endif
  5032. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5033. //DEBUG_INFO(" debug 5 -1\n");
  5034. //parsing strings to words
  5035. i = 0;
  5036. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5037. loc = loc+3+strlen("chargingSchedulePeriod");
  5038. pch = strtok(loc ,"{");
  5039. while (pch != NULL)
  5040. {
  5041. strcpy(SchedulePeriodList[i], pch);
  5042. pch = strtok (NULL, "{");
  5043. i = i + 1;
  5044. }
  5045. n_SchedulePeriods = i;
  5046. for(int i=0;i<n_SchedulePeriods;i++)
  5047. {
  5048. //*************startPeriod****************/
  5049. c = 0;
  5050. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5051. memset(sstr ,0, sizeof(sstr) );
  5052. while (loc[strlen("startPeriod")+2+c] != ',')
  5053. {
  5054. sstr[c] = loc[strlen("startPeriod")+2+c];
  5055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5056. c++;
  5057. }
  5058. sstr[c] = '\0';
  5059. tempStartPeriodInt = atoi(sstr);
  5060. //*************limit****************/
  5061. c = 0;
  5062. loc = strstr(SchedulePeriodList[i], "limit");
  5063. memset(sstr ,0, sizeof(sstr) );
  5064. while (loc[strlen("limit")+2+c] != ',')
  5065. {
  5066. sstr[c] = loc[strlen("limit")+2+c];
  5067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5068. c++;
  5069. }
  5070. sstr[c] = '\0';
  5071. tempLimitInt = atof(sstr);
  5072. //*************numberPhases****************/
  5073. c = 0;
  5074. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5075. memset(sstr ,0, sizeof(sstr) );
  5076. while (loc[strlen("numberPhases")+2+c] != '}')
  5077. {
  5078. sstr[c] = loc[strlen("numberPhases")+2+c];
  5079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5080. c++;
  5081. }
  5082. sstr[c] = '\0';
  5083. tempNumberPhasesInt = atoi(sstr);
  5084. if(j == 0)
  5085. {
  5086. ChargePointMaxProfile.Duration = tempdurationInt;
  5087. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5088. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5089. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5090. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5091. }
  5092. }
  5093. if(MinChargingRate < tempminChargingRateFloat)
  5094. {
  5095. MinChargingRate = tempminChargingRateFloat;
  5096. }
  5097. if(confirmPeriods < n_SchedulePeriods)
  5098. {
  5099. confirmPeriods = n_SchedulePeriods;
  5100. }
  5101. j = j + 1;
  5102. }
  5103. fclose(fptr1);
  5104. }
  5105. }// the end of access file ChargePointMaxProfile
  5106. //****************************TxDefaultProfile************************************************/
  5107. #if 0
  5108. switch(connectorIdInt)
  5109. {
  5110. case 0:
  5111. break;
  5112. case 1:
  5113. strcpy(fname, TxDefaultProfile_1_JSON );
  5114. break;
  5115. case 2:
  5116. strcpy(fname, TxDefaultProfile_2_JSON );
  5117. break;
  5118. default:
  5119. strcpy(fname, TxDefaultProfile_1_JSON );
  5120. break;
  5121. }
  5122. #endif
  5123. memset(fname, 0, sizeof fname);
  5124. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5125. TxDefaultProfileFileIsNull=TRUE;
  5126. if((access(fname,F_OK))!=-1)
  5127. {
  5128. fptr1 = fopen(fname, "r");
  5129. c = 0;
  5130. c = fgetc(fptr1);
  5131. //DEBUG_INFO("c:%d\n",c);
  5132. rewind(fptr1);
  5133. if(c == EOF)
  5134. {
  5135. DEBUG_INFO("\n End of file reached.");
  5136. TxDefaultProfileFileIsNull=TRUE;
  5137. fclose(fptr1);
  5138. }
  5139. else
  5140. {
  5141. TxDefaultProfileFileIsNull=FALSE;
  5142. while(fscanf(fptr1, "%s", word) != EOF)
  5143. {
  5144. if(strcmp(word, "chargingProfileId") == 0)
  5145. {
  5146. n_chargingProfile = n_chargingProfile + 1;
  5147. }
  5148. }
  5149. rewind(fptr1);
  5150. //search Charging Profile Element
  5151. int i = 0;
  5152. int j = 0;
  5153. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5154. //DEBUG_INFO(" 1-1\n");
  5155. #if 0
  5156. /***********connectorId****************/
  5157. c = 0;
  5158. loc = strstr(sLineWord, "connectorId");
  5159. memset(sstr ,0, sizeof(sstr) );
  5160. while (loc[strlen("connectorId")+2+c] != ',')
  5161. {
  5162. sstr[c] = loc[strlen("connectorId")+2+c];
  5163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5164. c++;
  5165. }
  5166. sstr[c] = '\0';
  5167. tempconnectorIdInt = atoi(sstr);
  5168. #endif
  5169. //***********validFrom**************/
  5170. c = 0;
  5171. loc = strstr(sLineWord, "validFrom");
  5172. if(loc != NULL)
  5173. {
  5174. memset(sstr ,0, sizeof(sstr) );
  5175. while (loc[3+strlen("validFrom")+c] != '\"')
  5176. {
  5177. sstr[c] = loc[3+strlen("validFrom")+c];
  5178. c++;
  5179. }
  5180. sstr[c] = '\0';
  5181. strcpy(tempvalidFromStr,sstr);
  5182. }
  5183. else
  5184. {
  5185. strcpy(tempvalidFromStr,"");
  5186. }
  5187. //***********validFrom**************/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "duration");
  5190. if(loc != NULL)
  5191. {
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[2+strlen("duration")+c] != ',')
  5194. {
  5195. sstr[c] = loc[2+strlen("duration")+c];
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. tempdurationInt = atoi(sstr);
  5200. }
  5201. else
  5202. {
  5203. tempdurationInt = 0;
  5204. }
  5205. //**********startSchedule**********/
  5206. c = 0;
  5207. loc = strstr(sLineWord, "startSchedule");
  5208. memset(sstr ,0, sizeof(sstr) );
  5209. while (loc[3+strlen("startSchedule")+c] != '\"')
  5210. {
  5211. sstr[c] = loc[3+strlen("startSchedule")+c];
  5212. c++;
  5213. }
  5214. sstr[c] = '\0';
  5215. strcpy(tempstartScheduleStr, sstr);
  5216. strcpy(TxDefaultProfileScheduleStr, sstr);
  5217. //**********chargingRateUnit**********/
  5218. c = 0;
  5219. loc = strstr(sLineWord, "chargingRateUnit");
  5220. memset(sstr ,0, sizeof(sstr) );
  5221. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5222. {
  5223. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5224. c++;
  5225. }
  5226. sstr[c] = '\0';
  5227. strcpy(tempchargingRateUnitStr, sstr);
  5228. //**********minChargingRate*******/
  5229. c = 0;
  5230. loc = strstr(sLineWord, "minChargingRate");
  5231. if(loc != NULL)
  5232. {
  5233. memset(sstr ,0, sizeof(sstr) );
  5234. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5235. {
  5236. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5237. c++;
  5238. }
  5239. sstr[c] = '\0';
  5240. tempminChargingRateFloat = atof(sstr);
  5241. }
  5242. else
  5243. {
  5244. tempminChargingRateFloat = 0.0;
  5245. }
  5246. #if 0
  5247. //
  5248. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5249. tp.tm_isdst = -1;
  5250. time_t utc = mktime(&tp);
  5251. time_t t = time(NULL);
  5252. //diff_t = difftime(t, utc);
  5253. #endif
  5254. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5255. //parsing strings to words
  5256. i = 0;
  5257. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5258. loc = loc+3+strlen("chargingSchedulePeriod");
  5259. pch = strtok(loc ,"{");
  5260. while (pch != NULL)
  5261. {
  5262. strcpy(SchedulePeriodList[i], pch);
  5263. pch = strtok (NULL, "{");
  5264. i = i + 1;
  5265. }
  5266. n_SchedulePeriods = i;
  5267. for(int i=0;i<n_SchedulePeriods;i++)
  5268. {
  5269. //*************startPeriod****************/
  5270. c = 0;
  5271. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5272. memset(sstr ,0, sizeof(sstr) );
  5273. while (loc[strlen("startPeriod")+2+c] != ',')
  5274. {
  5275. sstr[c] = loc[strlen("startPeriod")+2+c];
  5276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5277. c++;
  5278. }
  5279. sstr[c] = '\0';
  5280. tempStartPeriodInt = atoi(sstr);
  5281. //*************limit****************/
  5282. c = 0;
  5283. loc = strstr(SchedulePeriodList[i], "limit");
  5284. memset(sstr ,0, sizeof(sstr) );
  5285. while (loc[strlen("limit")+2+c] != ',')
  5286. {
  5287. sstr[c] = loc[strlen("limit")+2+c];
  5288. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5289. c++;
  5290. }
  5291. sstr[c] = '\0';
  5292. tempLimitInt = atof(sstr);
  5293. //*************numberPhases****************/
  5294. c = 0;
  5295. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5296. memset(sstr ,0, sizeof(sstr) );
  5297. while (loc[strlen("numberPhases")+2+c] != '}')
  5298. {
  5299. sstr[c] = loc[strlen("numberPhases")+2+c];
  5300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5301. c++;
  5302. }
  5303. sstr[c] = '\0';
  5304. tempNumberPhasesInt = atoi(sstr);
  5305. if(j == 0)
  5306. {
  5307. TxDefaultProfile.Duration = tempdurationInt;
  5308. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5309. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5310. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5311. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5312. }
  5313. else
  5314. {
  5315. //other stack level charging Profile
  5316. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5317. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5318. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5319. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5320. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5321. }
  5322. }
  5323. if(MinChargingRate < tempminChargingRateFloat)
  5324. MinChargingRate = tempminChargingRateFloat;
  5325. if(confirmPeriods < n_SchedulePeriods)
  5326. confirmPeriods = n_SchedulePeriods;
  5327. j = j + 1;
  5328. //DEBUG_INFO(" 1-2\n");
  5329. }
  5330. fclose(fptr1);
  5331. //Stacking Charging Profiles
  5332. for(int l=0; l <(j-1) ;l++)
  5333. {
  5334. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5335. {
  5336. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5337. {
  5338. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5339. {
  5340. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5341. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5342. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5343. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5344. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5345. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5346. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5347. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5348. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5349. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5350. }
  5351. else
  5352. {
  5353. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5354. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5355. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5356. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5357. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5358. }
  5359. }
  5360. }
  5361. }
  5362. //end of Stacking Charging Profiles
  5363. }
  5364. }// the end of ACCESS TxDefaultProfile
  5365. //****************************TxProfile************************************************/
  5366. #if 0
  5367. switch(connectorIdInt)
  5368. {
  5369. case 0:
  5370. break;
  5371. case 1:
  5372. strcpy(fname, TxProfile_1_JSON );
  5373. break;
  5374. case 2:
  5375. strcpy(fname, TxProfile_2_JSON );
  5376. break;
  5377. default:
  5378. strcpy(fname, TxProfile_1_JSON );
  5379. break;
  5380. }
  5381. #endif
  5382. memset(fname, 0, sizeof fname);
  5383. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5384. TxProfileIsNull=TRUE;
  5385. if((access(fname,F_OK))!=-1)
  5386. {
  5387. fptr1 = fopen(fname, "r");
  5388. c = 0;
  5389. c = fgetc(fptr1);
  5390. //DEBUG_INFO("c:%d\n",c);
  5391. rewind(fptr1);
  5392. if(c == EOF)
  5393. {
  5394. DEBUG_INFO("\n End of file reached.");
  5395. TxProfileIsNull=TRUE;
  5396. fclose(fptr1);
  5397. }
  5398. else
  5399. {
  5400. TxProfileIsNull=FALSE;
  5401. while(fscanf(fptr1, "%s", word) != EOF)
  5402. {
  5403. if(strcmp(word, "chargingProfileId") == 0)
  5404. {
  5405. n_chargingProfile = n_chargingProfile + 1;
  5406. }
  5407. }
  5408. rewind(fptr1);
  5409. //search Charging Profile Element
  5410. int i= 0;
  5411. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5412. #if 0
  5413. /***********connectorId****************/
  5414. c = 0;
  5415. loc = strstr(sLineWord, "connectorId");
  5416. memset(sstr ,0, sizeof(sstr) );
  5417. while (loc[strlen("connectorId")+2+c] != ',')
  5418. {
  5419. sstr[c] = loc[strlen("connectorId")+2+c];
  5420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5421. c++;
  5422. }
  5423. sstr[c] = '\0';
  5424. tempconnectorIdInt = atoi(sstr);
  5425. #endif
  5426. //***********validFrom**************/
  5427. c = 0;
  5428. loc = strstr(sLineWord, "validFrom");
  5429. if(loc != NULL)
  5430. {
  5431. memset(sstr ,0, sizeof(sstr) );
  5432. while (loc[3+strlen("validFrom")+c] != '\"')
  5433. {
  5434. sstr[c] = loc[3+strlen("validFrom")+c];
  5435. c++;
  5436. }
  5437. sstr[c] = '\0';
  5438. strcpy(tempvalidFromStr,sstr);
  5439. }
  5440. else
  5441. {
  5442. strcpy(tempvalidFromStr,"");
  5443. }
  5444. //**********startSchedule**********/
  5445. c = 0;
  5446. loc = strstr(sLineWord, "startSchedule");
  5447. memset(sstr ,0, sizeof(sstr) );
  5448. while (loc[3+strlen("startSchedule")+c] != '\"')
  5449. {
  5450. sstr[c] = loc[3+strlen("startSchedule")+c];
  5451. c++;
  5452. }
  5453. sstr[c] = '\0';
  5454. strcpy(tempstartScheduleStr, sstr);
  5455. strcpy(TxProfileScheduleStr, sstr);
  5456. //**********chargingRateUnit**********/
  5457. c = 0;
  5458. loc = strstr(sLineWord, "chargingRateUnit");
  5459. memset(sstr ,0, sizeof(sstr) );
  5460. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5461. {
  5462. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5463. c++;
  5464. }
  5465. sstr[c] = '\0';
  5466. strcpy(tempchargingRateUnitStr, sstr);
  5467. //**********minChargingRate*******/
  5468. c = 0;
  5469. loc = strstr(sLineWord, "minChargingRate");
  5470. if(loc != NULL)
  5471. {
  5472. memset(sstr ,0, sizeof(sstr) );
  5473. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5474. {
  5475. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5476. c++;
  5477. }
  5478. sstr[c] = '\0';
  5479. tempminChargingRateFloat = atof(sstr);
  5480. }
  5481. else
  5482. {
  5483. tempminChargingRateFloat = 0.0;
  5484. }
  5485. #if 0
  5486. //
  5487. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5488. tp.tm_isdst = -1;
  5489. time_t utc = mktime(&tp);
  5490. time_t t = time(NULL);
  5491. //diff_t = difftime(t, utc);
  5492. #endif
  5493. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5494. //parsing strings to words
  5495. i = 0;
  5496. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5497. loc = loc+3+strlen("chargingSchedulePeriod");
  5498. pch = strtok(loc ,"{");
  5499. while (pch != NULL)
  5500. {
  5501. strcpy(SchedulePeriodList[i], pch);
  5502. pch = strtok (NULL, "{");
  5503. i = i + 1;
  5504. }
  5505. n_SchedulePeriods = i;
  5506. for(int i=0;i<n_SchedulePeriods;i++)
  5507. {
  5508. //*************startPeriod****************/
  5509. c = 0;
  5510. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5511. memset(sstr ,0, sizeof(sstr) );
  5512. while (loc[strlen("startPeriod")+2+c] != ',')
  5513. {
  5514. sstr[c] = loc[strlen("startPeriod")+2+c];
  5515. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5516. c++;
  5517. }
  5518. sstr[c] = '\0';
  5519. tempStartPeriodInt = atoi(sstr);
  5520. //*************limit****************/
  5521. c = 0;
  5522. loc = strstr(SchedulePeriodList[i], "limit");
  5523. memset(sstr ,0, sizeof(sstr) );
  5524. while (loc[strlen("limit")+2+c] != ',')
  5525. {
  5526. sstr[c] = loc[strlen("limit")+2+c];
  5527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. tempLimitInt = atof(sstr);
  5532. //*************numberPhases****************/
  5533. c = 0;
  5534. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5535. memset(sstr ,0, sizeof(sstr) );
  5536. while (loc[strlen("numberPhases")+2+c] != '}')
  5537. {
  5538. sstr[c] = loc[strlen("numberPhases")+2+c];
  5539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5540. c++;
  5541. }
  5542. sstr[c] = '\0';
  5543. tempNumberPhasesInt = atoi(sstr);
  5544. TxProfile.Duration = durationInt;
  5545. TxProfile.TotalPeriod = n_SchedulePeriods;
  5546. TxProfile.Period[i].Limit = tempLimitInt;
  5547. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5548. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5549. }
  5550. if(MinChargingRate < tempminChargingRateFloat)
  5551. MinChargingRate = tempminChargingRateFloat;
  5552. if(confirmPeriods < n_SchedulePeriods)
  5553. confirmPeriods = n_SchedulePeriods;
  5554. }
  5555. fclose(fptr1);
  5556. }
  5557. }// the end of ACCESS TxProfile
  5558. //CompositeSchedule
  5559. int period=0;
  5560. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5561. {
  5562. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5563. struct tm tp;
  5564. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5565. tp.tm_isdst = -1;
  5566. time_t utc = mktime(&tp);
  5567. time_t t = time(NULL);
  5568. double diff_f = difftime(t, utc);
  5569. int diff_i; // = (int)diff_f;
  5570. int quotient; // = diff_i / 86400;//86400 seconds/day
  5571. //int remainder = diff_i % 86400;
  5572. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5573. {
  5574. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5575. {
  5576. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5577. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5578. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5579. period = period + 1;
  5580. }
  5581. else
  5582. {
  5583. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5584. {
  5585. }
  5586. else
  5587. {
  5588. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5589. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5590. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5591. period = period + 1;
  5592. }
  5593. }
  5594. }
  5595. if( diff_f >= 0)
  5596. {
  5597. diff_i = (int)diff_f;
  5598. quotient = diff_i / 86400;//86400 seconds/day
  5599. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5600. {
  5601. 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))
  5602. {
  5603. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5604. {
  5605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5606. }
  5607. else
  5608. {
  5609. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5610. }
  5611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5612. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5613. period = period + 1;
  5614. }
  5615. }
  5616. // Check Last Period
  5617. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5618. {
  5619. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5620. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5621. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5622. period = period + 1;
  5623. }
  5624. } // diff_f >= 0
  5625. }
  5626. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5627. {
  5628. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5629. struct tm tp;
  5630. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5631. tp.tm_isdst = -1;
  5632. time_t utc = mktime(&tp);
  5633. time_t t = time(NULL);
  5634. double diff_f = difftime(t, utc);
  5635. int diff_i;// = (int)diff_f;
  5636. int quotient; // = diff_i / 86400;//86400 seconds/day
  5637. //int remainder = diff_i % 86400;
  5638. if(diff_f >= 0)
  5639. {
  5640. diff_i = (int)diff_f;
  5641. quotient = diff_i / 86400;//86400 seconds/day
  5642. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5643. {
  5644. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5645. {
  5646. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5647. {
  5648. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5649. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5650. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5651. period = period + 1;
  5652. }
  5653. else
  5654. {
  5655. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].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. }
  5661. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5662. {
  5663. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5664. {
  5665. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5666. {
  5667. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5668. {
  5669. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5671. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5672. period = period + 1;
  5673. }
  5674. else
  5675. {
  5676. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5677. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5678. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5679. period = period + 1;
  5680. }
  5681. }
  5682. }
  5683. }
  5684. }
  5685. } // end diff_f >= 0
  5686. }
  5687. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5688. {
  5689. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5690. struct tm tp;
  5691. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5692. tp.tm_isdst = -1;
  5693. time_t utc = mktime(&tp);
  5694. time_t t = time(NULL);
  5695. double diff_f = difftime(t, utc);
  5696. int diff_i; // = (int)diff_f;
  5697. int quotient; // = diff_i / 86400;//86400 seconds/day
  5698. //int remainder = diff_i % 86400;
  5699. if(diff_f >= 0)
  5700. {
  5701. diff_i = (int)diff_f;
  5702. quotient = diff_i / 86400;//86400 seconds/day
  5703. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5704. {
  5705. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5706. {
  5707. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5708. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5709. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5710. period = period + 1;
  5711. }
  5712. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5713. {
  5714. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5715. {
  5716. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5717. {
  5718. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5719. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5720. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5721. period = period + 1;
  5722. }
  5723. }
  5724. }
  5725. }
  5726. } // diff_f >= 0
  5727. }
  5728. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5729. {
  5730. confirmPeriods = 0;
  5731. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5732. goto end;
  5733. }
  5734. confirmPeriods = period;
  5735. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5736. //---- Define StartSchedule----/
  5737. struct tm *gtime;
  5738. time_t now;
  5739. char buf[28];
  5740. //---Read the current system time---/
  5741. time(&now);
  5742. //---Convert the system time to GMT (now UTC)---/
  5743. gtime = gmtime(&now);
  5744. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5745. // make .conf
  5746. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5747. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5748. //DEBUG_INFO(" debug 11\n");
  5749. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5750. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5751. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5752. }
  5753. else
  5754. {
  5755. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5756. }
  5757. end:
  5758. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5759. return result;
  5760. }
  5761. int handleGetConfigurationRequest(char *uuid, char *payload)
  5762. {
  5763. mtrace();
  5764. int result = FAIL;
  5765. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5766. //struct json_object *jsonitem;
  5767. int MaxKeySupported = 0;
  5768. int n_keys = 0;
  5769. char requestKey[43][50]={0};
  5770. char search[]="[";
  5771. char sstr[500]={ 0 };
  5772. //int pos;
  5773. int l, c = 0;
  5774. int i = 0;
  5775. char *delim = "\",\"";
  5776. char * pch;
  5777. char *loc = strstr(payload, search);
  5778. //********************* Parsing String ***********************************/
  5779. if(loc == NULL) {
  5780. DEBUG_INFO("no key match in Configuration \n");
  5781. }
  5782. else {
  5783. //pos = loc - payload;
  5784. l = strlen(loc)-4;
  5785. while (c < l)
  5786. {
  5787. sstr[c] = loc[c+2];
  5788. c++;
  5789. }
  5790. sstr[c] = '\0';
  5791. //parsing strings to words
  5792. pch = strtok(sstr,delim);
  5793. if(pch == NULL)
  5794. {
  5795. strcpy(requestKey[0], sstr);
  5796. }
  5797. else
  5798. {
  5799. while (pch != NULL)
  5800. {
  5801. strcpy(requestKey[i], pch);
  5802. pch = strtok (NULL, delim);
  5803. i = i + 1;
  5804. }
  5805. n_keys = i;
  5806. }
  5807. }
  5808. UnknownKeynum = 0;
  5809. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5810. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5811. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5812. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5813. if(n_keys != 0)
  5814. {
  5815. for(int i=0;i<n_keys;i++)
  5816. {
  5817. getKeyValue(requestKey[i]);
  5818. //json_object_put(jsonitem);
  5819. }
  5820. }
  5821. else
  5822. {
  5823. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5824. getKeyValue("");
  5825. }
  5826. processUnkownKey();
  5827. sendGetConfigurationConfirmation(uuid);
  5828. return result;
  5829. }
  5830. static char fnamePlusPath[100]={0};
  5831. static char fnamePWithNoPath[60]={0};
  5832. void checkUploadLog(void)
  5833. {
  5834. FILE *fp;
  5835. /* Open the command for reading. */
  5836. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5837. if (fp == NULL) {
  5838. printf("Failed to run command\n" );
  5839. exit(1);
  5840. }
  5841. int ftppathlen = 0;
  5842. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5843. int i = 0;
  5844. /* Read the output a line at a time - output it. */
  5845. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5846. if(i==0)
  5847. {
  5848. ftppathlen = strlen(fnamePlusPath);
  5849. printf("%s\n", fnamePlusPath);
  5850. fnamePlusPath[ftppathlen]='\0';
  5851. break;
  5852. }
  5853. i= i+1;
  5854. }
  5855. /* close */
  5856. pclose(fp);
  5857. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5858. {
  5859. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5860. {
  5861. fnamePlusPath[k]='\0';
  5862. }
  5863. }
  5864. i=1;
  5865. //char fname[60]={0};
  5866. while(i < ftppathlen)
  5867. {
  5868. int len=ftppathlen-i;
  5869. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5870. {
  5871. printf("compare '/' all right\n");
  5872. break;
  5873. }
  5874. i=i+1;
  5875. }
  5876. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5877. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5878. fnamePWithNoPath[i+1] = '\0';
  5879. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5880. {
  5881. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5882. {
  5883. fnamePWithNoPath[j]='\0';
  5884. }
  5885. }
  5886. FILE* fp1 = fopen(fnamePlusPath, "r");
  5887. if (fp1)
  5888. {
  5889. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5890. // file exists
  5891. fclose(fp1);
  5892. }
  5893. else
  5894. {
  5895. // file doesn't exist
  5896. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5897. }
  5898. }
  5899. static char GetDiagnosticspayloadData[300]={0};
  5900. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. pthread_t t; // pthread 變數
  5905. system("exec /root/logPackTools 'log' 6");
  5906. #if 0
  5907. //char buffer [128];
  5908. time (&rawtime);
  5909. //printf("%ld\n", rawtime);
  5910. timeinfo = localtime (&rawtime);
  5911. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5912. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5913. if((access(fnamePlusPath,F_OK))!=-1)
  5914. {
  5915. DEBUG_INFO("fnamePlusPath exist.\n");
  5916. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5917. }
  5918. else
  5919. {
  5920. DEBUG_INFO("fnamePlusPath not exist!\n");
  5921. }
  5922. #endif
  5923. checkUploadLog();
  5924. memset(GetDiagnosticspayloadData, 0, 300);
  5925. strcpy(GetDiagnosticspayloadData, payload);
  5926. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5927. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5928. return result;
  5929. }
  5930. void* GetDiagnosticsProcess(void* data)
  5931. {
  5932. pthread_detach(pthread_self());
  5933. mtrace();
  5934. int retriesInt=0, retryIntervalInt=0;
  5935. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5936. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5937. 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};
  5938. int port=0;
  5939. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5940. int c = 0;
  5941. char *loc;
  5942. int isSuccess = FALSE;
  5943. char ftpbuf[200]={0};
  5944. //char temp[100]={0};
  5945. char * pch;
  5946. // [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"}]
  5947. char str[300]={ 0 };
  5948. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5949. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5950. DEBUG_INFO("GetDiagnosticsProcess\n");
  5951. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5952. //****************location*******************/
  5953. c = 0;
  5954. memset(sstr ,0, sizeof(sstr) );
  5955. loc = strstr(str, "location");
  5956. while (loc[3+strlen("location")+c] != '\"')
  5957. {
  5958. sstr[c] = loc[3+strlen("location")+c];
  5959. c++;
  5960. }
  5961. sstr[c] = '\0';
  5962. strcpy(locationstr,sstr);
  5963. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5964. if(strcmp(locationstr,"")==0)
  5965. {
  5966. DEBUG_INFO("location is <Empty>!\n");
  5967. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5968. goto end;
  5969. }
  5970. //****************retries*******************/
  5971. c = 0;
  5972. loc = strstr(str, "retries");
  5973. if(loc == NULL)
  5974. {
  5975. retriesIsNULL = TRUE;
  5976. }
  5977. else
  5978. {
  5979. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5980. {
  5981. sstr[c] = loc[strlen("retries")+2+c];
  5982. c++;
  5983. }
  5984. sstr[c] = '\0';
  5985. retriesInt = atoi(sstr);
  5986. }
  5987. if(retriesIsNULL == TRUE)
  5988. {
  5989. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5990. }
  5991. //****************retryInterval*******************/
  5992. c = 0;
  5993. loc = strstr(str, "retryInterval");
  5994. if(loc == NULL)
  5995. {
  5996. retryIntervalIsNULL = TRUE;
  5997. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5998. }
  5999. else
  6000. {
  6001. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6002. {
  6003. sstr[c] = loc[strlen("retryInterval")+2+c];
  6004. c++;
  6005. }
  6006. sstr[c] = '\0';
  6007. retryIntervalInt = atoi(sstr);
  6008. }
  6009. //****************startTime*******************/
  6010. c = 0;
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. loc = strstr(str, "startTime");
  6013. if(loc == NULL)
  6014. {
  6015. startTimeIsNULL = TRUE;
  6016. }
  6017. else
  6018. {
  6019. while (loc[3+strlen("startTime")+c] != '\"')
  6020. {
  6021. sstr[c] = loc[3+strlen("startTime")+c];
  6022. c++;
  6023. }
  6024. sstr[c] = '\0';
  6025. strcpy(startTimestr,sstr);
  6026. }
  6027. //****************stopTime*******************/
  6028. c = 0;
  6029. memset(sstr ,0, sizeof(sstr) );
  6030. loc = strstr(str, "stopTime");
  6031. if(loc == NULL)
  6032. {
  6033. stopTimeIsNULL = TRUE;
  6034. }
  6035. else
  6036. {
  6037. while (loc[3+strlen("stopTime")+c] != '\"')
  6038. {
  6039. sstr[c] = loc[3+strlen("stopTime")+c];
  6040. c++;
  6041. }
  6042. sstr[c] = '\0';
  6043. strcpy(stopTimestr,sstr);
  6044. }
  6045. memset(protocol, 0, sizeof(protocol));
  6046. memset(user, 0, sizeof(user) );
  6047. memset(password, 0, sizeof(password));
  6048. memset(host, 0, sizeof(host));
  6049. memset(path, 0, sizeof(path));
  6050. memset(ftppath, 0, sizeof(ftppath));
  6051. memset(host1, 0, sizeof(host1));
  6052. memset(path1, 0, sizeof(path1));
  6053. /*location: ftp://user:password@host:port/path*/
  6054. #if 0
  6055. time_t rawtime;
  6056. struct tm * timeinfo;
  6057. //char buffer [128];
  6058. time (&rawtime);
  6059. //printf("%ld\n", rawtime);
  6060. timeinfo = localtime (&rawtime);
  6061. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6062. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6063. #endif
  6064. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6065. if((access(fnamePlusPath,F_OK))!=-1)
  6066. {
  6067. DEBUG_INFO("fnamePlusPath exist.\n");
  6068. }
  6069. else
  6070. {
  6071. DEBUG_INFO("fnamePlusPath not exist!\n");
  6072. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6073. goto end;
  6074. }
  6075. pch=strchr(locationstr,'@');
  6076. if(pch==NULL)
  6077. {
  6078. sscanf(locationstr,
  6079. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6080. protocol, host, &port, path);
  6081. strcpy(user,"anonymous");
  6082. strcpy(password,"");
  6083. }
  6084. else
  6085. {
  6086. //DEBUG_INFO("pch=%s\n", pch);
  6087. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6088. protocol, user, password, host, &port, path);
  6089. }
  6090. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6091. {
  6092. DEBUG_INFO("protocol is not ftp/http ! \n");
  6093. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6094. goto end;
  6095. }
  6096. if(strncmp(locationstr,"http", 4) == 0)
  6097. {
  6098. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6099. sprintf(ftppath,"/%s", path);
  6100. do{
  6101. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6102. sleep(retryIntervalInt);
  6103. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6104. if(!isSuccess)
  6105. {
  6106. DEBUG_INFO("Diagnostics fail.\n");
  6107. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6108. }
  6109. else
  6110. {
  6111. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6112. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6113. }
  6114. }
  6115. else
  6116. {
  6117. sscanf(host,"%[^/]%s",host1, path1);
  6118. sprintf(ftppath,"%s", path1);
  6119. int ftppathlen=strlen(ftppath);
  6120. int i=1;
  6121. char filenametemp[50];
  6122. while(i < ftppathlen)
  6123. {
  6124. int len=ftppathlen-i;
  6125. if(ftppath[len]== 47) // '/' ascll code: 47
  6126. {
  6127. DEBUG_INFO("find '/' all right\n");
  6128. break;
  6129. }
  6130. i=i+1;
  6131. }
  6132. memset(filenametemp, 0, sizeof(filenametemp));
  6133. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6134. filenametemp[i+1] = 0;
  6135. memset(ftpbuf, 0, sizeof(ftpbuf));
  6136. if(port == 0)
  6137. port = 21;
  6138. do{
  6139. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6140. sleep(retryIntervalInt);
  6141. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6142. if(!isSuccess)
  6143. {
  6144. DEBUG_INFO("Diagnostics fail.\n");
  6145. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6146. }
  6147. else
  6148. {
  6149. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6150. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6151. }
  6152. }
  6153. end:
  6154. DiagnosticsStatusNotificationStatus = 0; //Idle
  6155. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6156. }
  6157. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6158. {
  6159. mtrace();
  6160. int result = FAIL;
  6161. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6162. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6163. {
  6164. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6165. localversion = -1;
  6166. }
  6167. else
  6168. {
  6169. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6170. OCPP_getListVerion();
  6171. }
  6172. //from db.OCPP_getListVerion
  6173. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6174. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6175. sendGetLocalListVersionConfirmation(uuid,"");
  6176. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6177. return result;
  6178. }
  6179. int handleRemoteStartRequest(char *uuid, char *payload)
  6180. {
  6181. mtrace();
  6182. int result = FAIL;
  6183. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6184. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6185. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6186. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6187. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6188. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6189. int chargingSchedulePeriodCount = 0;
  6190. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6191. int c = 0;
  6192. char *loc;
  6193. char comfirmstr[20]={0};
  6194. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6195. if(server_pending == TRUE)
  6196. {
  6197. return 0;
  6198. }
  6199. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6200. //**********connectorId****************/
  6201. c = 0;
  6202. memset(sstr ,0, sizeof(sstr) );
  6203. loc = strstr(payload, "connectorId");
  6204. if(loc == NULL)
  6205. {
  6206. connectorIdIsNULL = TRUE;
  6207. }
  6208. else
  6209. {
  6210. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6211. {
  6212. sstr[c] = loc[strlen("connectorId")+2+c];
  6213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6214. c++;
  6215. }
  6216. sstr[c] = '\0';
  6217. connectorIdInt = atoi(sstr);
  6218. }
  6219. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6220. {
  6221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6222. goto end;
  6223. }
  6224. //****************idTag*******************/
  6225. c = 0;
  6226. memset(sstr ,0, sizeof(sstr) );
  6227. loc = strstr(payload, "idTag");
  6228. while (loc[3+strlen("idTag")+c] != '\"')
  6229. {
  6230. sstr[c] = loc[3+strlen("idTag")+c];
  6231. c++;
  6232. }
  6233. sstr[c] = '\0';
  6234. strcpy(idTagstr,sstr);
  6235. //****************chargingProfile*******************/
  6236. c = 0;
  6237. memset(sstr ,0, sizeof(sstr) );
  6238. loc = strstr(payload, "chargingProfile");
  6239. if(loc == NULL)
  6240. {
  6241. chargingProfileIsNULL = TRUE;
  6242. }
  6243. else
  6244. {
  6245. //****************chargingProfileId*******************/
  6246. c=0;
  6247. loc = strstr(payload, "chargingProfileId");
  6248. memset(sstr ,0, sizeof(sstr) );
  6249. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6250. {
  6251. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6253. c++;
  6254. }
  6255. sstr[c] = '\0';
  6256. chargingProfileIdInt = atoi(sstr);
  6257. //****************transactionId*******************/
  6258. loc = strstr(payload, "transactionId");
  6259. if(loc == NULL)
  6260. {
  6261. transactionIdIsNULL = TRUE;
  6262. }
  6263. else
  6264. {
  6265. c=0;
  6266. memset(sstr ,0, sizeof(sstr) );
  6267. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6268. {
  6269. sstr[c] = loc[strlen("transactionId")+2+c];
  6270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6271. c++;
  6272. }
  6273. sstr[c] = '\0';
  6274. transactionIdInt = atoi(sstr);
  6275. }
  6276. //****************stackLevel*******************/
  6277. c=0;
  6278. loc = strstr(payload, "stackLevel");
  6279. memset(sstr ,0, sizeof(sstr) );
  6280. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6281. {
  6282. sstr[c] = loc[strlen("stackLevel")+2+c];
  6283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6284. c++;
  6285. }
  6286. sstr[c] = '\0';
  6287. stackLevelInt = atoi(sstr);
  6288. //****************chargingProfilePurpose*******************/
  6289. c = 0;
  6290. memset(sstr ,0, sizeof(sstr) );
  6291. loc = strstr(payload, "chargingProfilePurpose");
  6292. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6293. {
  6294. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6295. c++;
  6296. }
  6297. sstr[c] = '\0';
  6298. strcpy(chargingProfilePurposestr,sstr);
  6299. //****************chargingProfileKind*******************/
  6300. c = 0;
  6301. memset(sstr ,0, sizeof(sstr) );
  6302. loc = strstr(payload, "chargingProfileKind");
  6303. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6304. {
  6305. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6306. c++;
  6307. }
  6308. sstr[c] = '\0';
  6309. strcpy(chargingProfileKindstr,sstr);
  6310. //****************recurrencyKind*******************/
  6311. loc = strstr(payload, "recurrencyKind");
  6312. if(loc == NULL)
  6313. {
  6314. recurrencyKindIsNULL = TRUE;
  6315. }
  6316. else
  6317. {
  6318. c = 0;
  6319. memset(sstr ,0, sizeof(sstr) );
  6320. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6321. {
  6322. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6323. c++;
  6324. }
  6325. sstr[c] = '\0';
  6326. strcpy(recurrencyKindstr,sstr);
  6327. }
  6328. //****************validFrom*******************/
  6329. loc = strstr(payload, "validFrom");
  6330. if(loc == NULL)
  6331. {
  6332. validFromIsNULL = TRUE;
  6333. }
  6334. else
  6335. {
  6336. c = 0;
  6337. memset(sstr ,0, sizeof(sstr) );
  6338. while (loc[3+strlen("validFrom")+c] != '\"')
  6339. {
  6340. sstr[c] = loc[3+strlen("validFrom")+c];
  6341. c++;
  6342. }
  6343. sstr[c] = '\0';
  6344. strcpy(validFromstr,sstr);
  6345. }
  6346. //****************validTo*******************/
  6347. loc = strstr(payload, "validTo");
  6348. if(loc == NULL)
  6349. {
  6350. validToIsNULL = TRUE;
  6351. }
  6352. else
  6353. {
  6354. c = 0;
  6355. memset(sstr ,0, sizeof(sstr) );
  6356. while (loc[3+strlen("validTo")+c] != '\"')
  6357. {
  6358. sstr[c] = loc[3+strlen("validTo")+c];
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. strcpy(validTostr,sstr);
  6363. }
  6364. //****************chargingSchedule*******************/
  6365. loc = strstr(payload, "chargingSchedule");
  6366. if(loc != NULL)
  6367. {
  6368. //****************duration*******************/
  6369. loc = strstr(payload, "duration");
  6370. if(loc == NULL)
  6371. {
  6372. durationIsNULL = TRUE;
  6373. }
  6374. else
  6375. {
  6376. c=0;
  6377. memset(sstr ,0, sizeof(sstr) );
  6378. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6379. {
  6380. sstr[c] = loc[strlen("duration")+2+c];
  6381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. durationInt = atoi(sstr);
  6386. }
  6387. //****************startSchedule******************/
  6388. loc = strstr(payload, "startSchedule");
  6389. if(loc == NULL)
  6390. {
  6391. startScheduleIsNULL = TRUE;
  6392. }
  6393. else
  6394. {
  6395. c = 0;
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. while (loc[3+strlen("startSchedule")+c] != '\"')
  6398. {
  6399. sstr[c] = loc[3+strlen("startSchedule")+c];
  6400. c++;
  6401. }
  6402. sstr[c] = '\0';
  6403. strcpy(startSchedulestr,sstr);
  6404. }
  6405. //****************chargingRateUnit*******************/
  6406. c = 0;
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. loc = strstr(payload, "chargingRateUnit");
  6409. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6410. {
  6411. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(chargingRateUnitstr,sstr);
  6416. //****************minChargingRate*******************/
  6417. loc = strstr(payload, "minChargingRate");
  6418. if(loc == NULL)
  6419. {
  6420. minChargingRateIsNULL = TRUE;
  6421. }
  6422. else
  6423. {
  6424. c=0;
  6425. memset(sstr ,0, sizeof(sstr) );
  6426. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6427. {
  6428. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6430. c++;
  6431. }
  6432. sstr[c] = '\0';
  6433. minChargingRateflaot = atof(sstr);
  6434. }
  6435. //****************chargingSchedulePeriod count*******************/
  6436. int what_len = strlen("startPeriod");
  6437. char *where = payload;
  6438. while ((where = strstr(where, "startPeriod"))) {
  6439. where += what_len;
  6440. chargingSchedulePeriodCount++;
  6441. }
  6442. where = payload;
  6443. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6444. {
  6445. //****************startPeriod*******************/
  6446. c=0;
  6447. loc = strstr(where, "startPeriod");
  6448. memset(sstr ,0, sizeof(sstr) );
  6449. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6450. {
  6451. sstr[c] = loc[strlen("startPeriod")+2+c];
  6452. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6453. c++;
  6454. }
  6455. sstr[c] = '\0';
  6456. startPeriodInt[periodNums] = atoi(sstr);
  6457. //****************limit*******************/
  6458. c=0;
  6459. loc = strstr(where, "limit");
  6460. memset(sstr ,0, sizeof(sstr) );
  6461. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6462. {
  6463. sstr[c] = loc[strlen("limit")+2+c];
  6464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6465. c++;
  6466. }
  6467. sstr[c] = '\0';
  6468. limitflaot[periodNums] = atof(sstr);
  6469. //****************numberPhases*******************/
  6470. loc = strstr(where, "numberPhases");
  6471. if(loc == NULL)
  6472. {
  6473. numberPhasesIsNULL = TRUE;
  6474. }
  6475. else
  6476. {
  6477. c=0;
  6478. memset(sstr ,0, sizeof(sstr) );
  6479. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6480. {
  6481. sstr[c] = loc[strlen("numberPhases")+2+c];
  6482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. numberPhasesInt[periodNums] = atoi(sstr);
  6487. }
  6488. where = loc;
  6489. }
  6490. }
  6491. }
  6492. /*
  6493. enum _SYSTEM_STATUS
  6494. {
  6495. S_BOOTING = 0,
  6496. S_IDLE, = 1
  6497. S_AUTHORIZING, =2
  6498. S_REASSIGN_CHECK, =3
  6499. S_REASSIGN, =4
  6500. S_PRECHARGE, =5
  6501. S_PREPARING_FOR_EV, =6
  6502. S_PREPARING_FOR_EVSE, =7
  6503. S_CHARGING, =8
  6504. S_TERMINATING, =9
  6505. S_COMPLETE, =10
  6506. S_ALARM, =11
  6507. S_FAULT =12
  6508. }
  6509. */
  6510. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6511. {
  6512. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6513. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6514. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6515. //check Transaction active
  6516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6517. {
  6518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6523. {
  6524. //Reserved
  6525. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6528. {
  6529. //Reserved
  6530. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6532. goto end;
  6533. }
  6534. else
  6535. {
  6536. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6537. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6538. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6539. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6540. {
  6541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6542. goto end;
  6543. }
  6544. }//END FOR ELSE
  6545. }
  6546. }// END FOR CHAdeMO_QUANTITY
  6547. for (int index = 0; index < CCS_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6550. {
  6551. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6552. {
  6553. //Reserved
  6554. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6555. }
  6556. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6557. {
  6558. //Reserved
  6559. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6561. goto end;
  6562. }
  6563. else
  6564. {
  6565. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6566. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6567. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6568. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6569. {
  6570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6571. goto end;
  6572. }
  6573. }// END FOR ELSE
  6574. }
  6575. }// END FOR CCS_QUANTITY
  6576. for (int index = 0; index < GB_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6581. {
  6582. //Reserved
  6583. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6584. }
  6585. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6586. {
  6587. //Reserved
  6588. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6590. goto end;
  6591. }
  6592. else
  6593. {
  6594. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6595. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6596. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6597. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6598. {
  6599. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6600. goto end;
  6601. }
  6602. }// END FOR ELSE
  6603. }
  6604. } // END FOR GB_QUANTITY
  6605. }
  6606. else
  6607. {
  6608. for (int index = 0; index < AC_QUANTITY; index++)
  6609. {
  6610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6611. {
  6612. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6613. {
  6614. //Reserved
  6615. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6616. }
  6617. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6618. {
  6619. //Reserved
  6620. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6621. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6622. goto end;
  6623. }
  6624. else
  6625. {
  6626. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6627. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6628. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6629. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6630. {
  6631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6632. goto end;
  6633. }
  6634. }//END FOR ELSE
  6635. }
  6636. }// END FOR AC_QUANTITY
  6637. }
  6638. if(chargingProfileIsNULL == FALSE)
  6639. {
  6640. //ChargingProfile
  6641. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6642. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6643. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6644. if(recurrencyKindIsNULL == FALSE) //OPTION
  6645. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6646. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6647. if(transactionIdIsNULL == FALSE) // OPTION
  6648. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6649. if(validFromIsNULL == FALSE) // OPTION
  6650. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6651. if(validToIsNULL == FALSE) //OPTION
  6652. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6653. //ChargingSchedule
  6654. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6655. if(durationIsNULL == FALSE) //OPTION
  6656. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6657. if(minChargingRateIsNULL == FALSE) //OPTION
  6658. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6659. if(startScheduleIsNULL == FALSE) //OPTION
  6660. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6661. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6662. {
  6663. //ChargingSchedulePeriod
  6664. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6665. if(numberPhasesIsNULL == FALSE)
  6666. {
  6667. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6668. }
  6669. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6670. }
  6671. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6672. {
  6673. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6675. //memset idTag
  6676. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6677. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6678. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6679. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6680. }
  6681. else
  6682. {
  6683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6684. }
  6685. }
  6686. else
  6687. {
  6688. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6690. //memset idTag
  6691. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6692. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6693. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6694. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6695. }
  6696. }
  6697. else
  6698. {
  6699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6700. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6701. }
  6702. end:
  6703. if(connectorIdIsNULL == FALSE)
  6704. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6705. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6706. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6707. //OCPP send RemoteStartConfirmation by first.
  6708. sendRemoteStartConfirmation(uuid, comfirmstr);
  6709. return result;
  6710. }
  6711. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6712. {
  6713. mtrace();
  6714. int result = FAIL;
  6715. int match = FALSE;
  6716. int GunNO = 0;
  6717. int transactionIdInt=0;
  6718. int transactionIdIsNULL= FALSE;
  6719. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6720. int c = 0;
  6721. char *loc;
  6722. char comfirmstr[20];
  6723. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6724. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6725. if(server_pending == TRUE)
  6726. {
  6727. return 0;
  6728. }
  6729. c=0;
  6730. loc = strstr(payload, "transactionId");
  6731. if(loc == NULL)
  6732. {
  6733. transactionIdIsNULL= TRUE;
  6734. }
  6735. else
  6736. {
  6737. memset(sstr ,0, sizeof(sstr) );
  6738. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6739. {
  6740. sstr[c] = loc[strlen("transactionId")+2+c];
  6741. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6742. c++;
  6743. }
  6744. sstr[c] = '\0';
  6745. transactionIdInt = atoi(sstr);
  6746. }
  6747. if(transactionIdIsNULL == FALSE)
  6748. {
  6749. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6750. {
  6751. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6752. {
  6753. //check Transaction active
  6754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6755. {
  6756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6759. {
  6760. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6761. {
  6762. match = TRUE;
  6763. GunNO = gun_index;
  6764. }
  6765. }
  6766. }// END FOR CHAdeMO_QUANTITY
  6767. for (int index = 0; index < CCS_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6770. {
  6771. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6772. {
  6773. match = TRUE;
  6774. GunNO = gun_index;
  6775. }
  6776. }
  6777. }// END FOR CCS_QUANTITY
  6778. for (int index = 0; index < GB_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6781. {
  6782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6783. {
  6784. match = TRUE;
  6785. GunNO = gun_index;
  6786. }
  6787. }
  6788. }// END FOR GB_QUANTITY
  6789. }
  6790. else
  6791. {
  6792. for (int index = 0; index < AC_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6795. {
  6796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6797. {
  6798. match = TRUE;
  6799. GunNO = gun_index;
  6800. }
  6801. }
  6802. }// END FOR CHAdeMO_QUANTITY
  6803. }// END FOR AC ELSE
  6804. }// CHECK IF ResponseTransactionId == transactionIdInt
  6805. }//END FOR
  6806. if( match == TRUE)
  6807. {
  6808. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6810. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6811. }
  6812. else
  6813. {
  6814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6815. }
  6816. }
  6817. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6818. return result;
  6819. }
  6820. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. int connectorIdInt=0, reservationIdInt=0;
  6825. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6826. char comfirmstr[20]={0};
  6827. char sstr[180]={ 0 };
  6828. int c = 0;
  6829. char *loc;
  6830. //char *ptr;
  6831. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6832. //***(1)connectorId ****/
  6833. c=0;
  6834. loc = strstr(payload, "connectorId");
  6835. memset(sstr ,0, sizeof(sstr) );
  6836. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6837. {
  6838. sstr[c] = loc[strlen("connectorId")+2+c];
  6839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6840. c++;
  6841. }
  6842. sstr[c] = '\0';
  6843. connectorIdInt = atoi(sstr);
  6844. //***(2)expiryDate ****/
  6845. loc = strstr(payload, "expiryDate");
  6846. memset(sstr ,0, sizeof(sstr) );
  6847. c = 0;
  6848. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6849. {
  6850. sstr[c] = loc[3+strlen("expiryDate")+c];
  6851. c++;
  6852. }
  6853. sstr[c] = '\0';
  6854. strcpy(expiryDatestr, sstr);
  6855. //***(3)idTag ****/
  6856. loc = strstr(payload, "idTag");
  6857. memset(sstr ,0, sizeof(sstr) );
  6858. c = 0;
  6859. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6860. {
  6861. sstr[c] = loc[3+strlen("idTag")+c];
  6862. c++;
  6863. }
  6864. sstr[c] = '\0';
  6865. strcpy(idTagstr, sstr);
  6866. //***(4)parentIdTag ****/
  6867. loc = strstr(payload, "parentIdTag");
  6868. memset(sstr ,0, sizeof(sstr) );
  6869. c = 0;
  6870. if(loc == NULL)
  6871. {
  6872. strcpy(parentIdTagstr, "");
  6873. }
  6874. else
  6875. {
  6876. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6877. {
  6878. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6879. c++;
  6880. }
  6881. sstr[c] = '\0';
  6882. strcpy(parentIdTagstr, sstr);
  6883. }
  6884. //***(5)reservationId ****/
  6885. c=0;
  6886. loc = strstr(payload, "reservationId");
  6887. memset(sstr ,0, sizeof(sstr) );
  6888. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6889. {
  6890. sstr[c] = loc[strlen("reservationId")+2+c];
  6891. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6892. c++;
  6893. }
  6894. sstr[c] = '\0';
  6895. reservationIdInt = atoi(sstr);
  6896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6897. /*
  6898. enum SYSTEM_STATUS
  6899. {
  6900. SYS_MODE_BOOTING = 0,
  6901. SYS_MODE_IDLE = 1,
  6902. SYS_MODE_AUTHORIZING = 2,
  6903. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6904. SYS_MODE_REASSIGN = 4,
  6905. SYS_MODE_PREPARING = 5,
  6906. SYS_MODE_PREPARE_FOR_EV = 6,
  6907. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6908. SYS_MODE_CHARGING = 8,
  6909. SYS_MODE_TERMINATING = 9,
  6910. SYS_MODE_COMPLETE = 10,
  6911. SYS_MODE_ALARM = 11,
  6912. SYS_MODE_FAULT = 12,
  6913. SYS_MODE_RESERVATION = 13,
  6914. SYS_MODE_BOOKING = 14,
  6915. SYS_MODE_MAINTAIN = 15,
  6916. SYS_MODE_DEBUG = 16,
  6917. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6918. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6919. SYS_MODE_UPDATE = 19
  6920. };
  6921. */
  6922. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6923. {
  6924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6925. goto end;
  6926. }
  6927. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6928. {
  6929. //check Transaction active
  6930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6931. {
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6935. {
  6936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6937. {
  6938. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6939. {
  6940. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6941. {
  6942. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6944. }
  6945. 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'))
  6946. {
  6947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6948. }
  6949. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6950. {
  6951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6952. }
  6953. else
  6954. {
  6955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6956. }
  6957. }
  6958. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6959. {
  6960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6961. }
  6962. }
  6963. else
  6964. {
  6965. //replace reservation
  6966. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6968. }
  6969. }
  6970. } // END FOR CHAdeMO_QUANTITY
  6971. for (int index = 0; index < CCS_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6974. {
  6975. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6976. {
  6977. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6979. {
  6980. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6981. {
  6982. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6984. }
  6985. 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'))
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6988. }
  6989. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6990. {
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6992. }
  6993. else
  6994. {
  6995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6996. }
  6997. }
  6998. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6999. {
  7000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7001. }
  7002. }
  7003. else
  7004. {
  7005. //replace reservation
  7006. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7008. }
  7009. }
  7010. } // END FOR CCS_QUANTITY
  7011. for (int index = 0; index < GB_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7014. {
  7015. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7016. {
  7017. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7018. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7019. {
  7020. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7021. {
  7022. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7024. }
  7025. 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'))
  7026. {
  7027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7028. }
  7029. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7030. {
  7031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7032. }
  7033. else
  7034. {
  7035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7036. }
  7037. }
  7038. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7039. {
  7040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7041. }
  7042. }
  7043. else
  7044. {
  7045. //replace reservation
  7046. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7048. }
  7049. }
  7050. }// END FOR GB_QUANTITY
  7051. }
  7052. else
  7053. {
  7054. for (int index = 0; index < AC_QUANTITY; index++)
  7055. {
  7056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7057. {
  7058. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7059. {
  7060. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7061. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7062. {
  7063. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7064. {
  7065. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7067. }
  7068. 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'))
  7069. {
  7070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7071. }
  7072. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7073. {
  7074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7075. }
  7076. else
  7077. {
  7078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7079. }
  7080. }
  7081. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7082. {
  7083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7084. }
  7085. }
  7086. else
  7087. {
  7088. //replace reservation
  7089. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7091. }
  7092. }
  7093. } // END FOR AC_QUANTITY
  7094. }//END FOR AC ELSE
  7095. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7096. }
  7097. else if(connectorIdInt == 0)
  7098. {
  7099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7100. {
  7101. //check Transaction active
  7102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7103. {
  7104. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7105. {
  7106. 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'))
  7107. {
  7108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7109. goto end;
  7110. }
  7111. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7112. {
  7113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7114. goto end;
  7115. }
  7116. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7117. {
  7118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7119. goto end;
  7120. }
  7121. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7122. {
  7123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7124. goto end;
  7125. }
  7126. }
  7127. }// END FOR CHAdeMO_QUANTITY
  7128. for (int index = 0; index < CCS_QUANTITY; index++)
  7129. {
  7130. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7131. {
  7132. 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'))
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7135. }
  7136. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7137. {
  7138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7139. }
  7140. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7141. {
  7142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7143. }
  7144. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7145. {
  7146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7147. }
  7148. }
  7149. } // END FOR CCS_QUANTITY
  7150. for (int index = 0; index < GB_QUANTITY; index++)
  7151. {
  7152. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7153. {
  7154. 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'))
  7155. {
  7156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7157. }
  7158. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7159. {
  7160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7161. }
  7162. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7163. {
  7164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7165. }
  7166. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7167. {
  7168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7169. }
  7170. }
  7171. } // END FOR GB_QUANTITY
  7172. }
  7173. else
  7174. {
  7175. for (int index = 0; index < AC_QUANTITY; index++)
  7176. {
  7177. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7178. {
  7179. 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'))
  7180. {
  7181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7182. goto end;
  7183. }
  7184. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7185. {
  7186. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7187. goto end;
  7188. }
  7189. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7190. {
  7191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7192. goto end;
  7193. }
  7194. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7195. {
  7196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7197. goto end;
  7198. }
  7199. }
  7200. }// END FOR AC_QUANTITY
  7201. }
  7202. //The connectorId is 0
  7203. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7205. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7206. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7207. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7208. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7209. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7210. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7211. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7212. result = TRUE;
  7213. return result;
  7214. }
  7215. else
  7216. {
  7217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7218. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7219. }
  7220. if(strcmp(comfirmstr,"Accepted") == 0)
  7221. {
  7222. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7223. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7224. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7225. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7226. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7227. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7228. result = TRUE;
  7229. return result;
  7230. }
  7231. end:
  7232. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7233. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7234. return result;
  7235. }
  7236. int handleResetRequest(char *uuid, char *payload)
  7237. {
  7238. mtrace();
  7239. int result = FAIL;
  7240. char sstr[10]={0};
  7241. char typestr[10]={0};
  7242. char comfirmstr[20]={0};
  7243. int c = 0;
  7244. char *loc;
  7245. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7246. DEBUG_INFO("handleResetRequest ...\n");
  7247. loc = strstr(payload, "type");
  7248. memset(sstr ,0, sizeof(sstr) );
  7249. c = 0;
  7250. while (loc[3+strlen("type")+c] != '\"')
  7251. {
  7252. sstr[c] = loc[3+strlen("type")+c];
  7253. c++;
  7254. }
  7255. sstr[c] = '\0';
  7256. strcpy(typestr,sstr);
  7257. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7258. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7259. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7260. {
  7261. //check Transaction active
  7262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7263. {
  7264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7265. {
  7266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7267. {
  7268. //0: unplug, 1: Plug-in
  7269. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7270. }
  7271. }
  7272. for (int index = 0; index < CCS_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7275. {
  7276. //0: unplug, 1: Plug-in
  7277. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7278. }
  7279. }
  7280. for (int index = 0; index < GB_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7283. {
  7284. //0: unplug, 1: Plug-in
  7285. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7286. }
  7287. }
  7288. }
  7289. else
  7290. {
  7291. for (int index = 0; index < AC_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7294. {
  7295. //0: unplug, 1: Plug-in
  7296. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7297. }
  7298. }
  7299. }// END FOR AC ELSE
  7300. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7301. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7302. result = TRUE;
  7303. return result;
  7304. }
  7305. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7306. {
  7307. //check Transaction active
  7308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7309. {
  7310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7313. {
  7314. //0: unplug, 1: Plug-in
  7315. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7316. }
  7317. }
  7318. for (int index = 0; index < CCS_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7321. {
  7322. //0: unplug, 1: Plug-in
  7323. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7324. }
  7325. }
  7326. for (int index = 0; index < GB_QUANTITY; index++)
  7327. {
  7328. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7329. {
  7330. //0: unplug, 1: Plug-in
  7331. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7332. }
  7333. }
  7334. }
  7335. else
  7336. {
  7337. for (int index = 0; index < AC_QUANTITY; index++)
  7338. {
  7339. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7340. {
  7341. //0: unplug, 1: Plug-in
  7342. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7343. }
  7344. }
  7345. }// END FOR AC ELSE
  7346. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7347. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7348. result = TRUE;
  7349. return result;
  7350. }
  7351. else
  7352. {
  7353. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7354. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7355. goto errorend;
  7356. }
  7357. errorend:
  7358. sendResetConfirmation(uuid, comfirmstr);
  7359. return result;
  7360. }
  7361. int handleSendLocalListRequest(char *uuid, char *payload)
  7362. {
  7363. mtrace();
  7364. int result = FAIL;
  7365. int listVersionInt;
  7366. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7367. char listsearch[]="listVersion";
  7368. char updateTypesearch[]="updateType";
  7369. char localAuthorizationListsearch[]="localAuthorizationList";
  7370. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7371. char CardList[500][160]={0};
  7372. char updateTypestr[15]={0};
  7373. char idTagstr[20]={0};
  7374. char parentIdTag[20]={0};
  7375. char expiryDate[30]={0};
  7376. char idTagstatus[16]={0};
  7377. int c = 0;
  7378. int i = 0;
  7379. char *delim1 = "}";
  7380. char * pch;
  7381. char *loc;
  7382. //char *ptr;
  7383. char comfirmstr[20];
  7384. //int n_localAuthorizations = 0;
  7385. int checkState_Faulted = FALSE;
  7386. DEBUG_INFO("handleSendLocalListRequest\n");
  7387. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7388. {
  7389. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7390. goto end;
  7391. }
  7392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7393. {
  7394. //check Charge Point state
  7395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7396. {
  7397. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7398. {
  7399. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7400. }
  7401. }
  7402. for (int index = 0; index < CCS_QUANTITY; index++)
  7403. {
  7404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7405. {
  7406. checkState_Faulted = TRUE; //OCPP Status
  7407. }
  7408. }
  7409. for (int index = 0; index < GB_QUANTITY; index++)
  7410. {
  7411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7412. {
  7413. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7414. }
  7415. }
  7416. }
  7417. else
  7418. {
  7419. //check Charge Point state
  7420. for (int index = 0; index < AC_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7423. {
  7424. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7425. }
  7426. }
  7427. }// END FOR AC ELSE
  7428. if(checkState_Faulted == TRUE)
  7429. {
  7430. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7431. goto end;
  7432. }
  7433. //listVersion
  7434. c = 0;
  7435. loc = strstr(payload, listsearch);
  7436. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7437. {
  7438. sstr[c] = loc[strlen("listVersion")+2+c];
  7439. c++;
  7440. }
  7441. sstr[c] = '\0';
  7442. listVersionInt = atoi(sstr);
  7443. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7444. //updateType
  7445. loc = strstr(payload, updateTypesearch);
  7446. c = 0;
  7447. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7448. {
  7449. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7450. c++;
  7451. }
  7452. sstr[c] = '\0';
  7453. strcpy(updateTypestr, sstr);
  7454. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7455. //localAuthorizationList
  7456. memset(sstr ,0, sizeof(sstr) );
  7457. loc = strstr(payload, localAuthorizationListsearch);
  7458. if(loc != NULL) // localAuthorizationList is not NULL
  7459. {
  7460. //Check UpdateType
  7461. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7462. {
  7463. //Local list full update
  7464. printf("Local list full update.\n");
  7465. OCPP_cleanLocalList();
  7466. }
  7467. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7468. {
  7469. //Local list different update
  7470. printf("Local list different update.\n");
  7471. OCPP_getListVerion();
  7472. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7473. {
  7474. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7475. goto end;
  7476. }
  7477. }
  7478. else
  7479. {
  7480. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7481. goto end;
  7482. }
  7483. c = 0;
  7484. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7485. {
  7486. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7487. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7488. c++;
  7489. }
  7490. sstr[c] = '\0';
  7491. //DEBUG_INFO("sstr=%s\n", sstr);
  7492. //parsing strings to words
  7493. i = 0;
  7494. pch = strtok(sstr,delim1);
  7495. while (pch != NULL)
  7496. {
  7497. strcpy(CardList[i], pch);
  7498. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7499. pch = strtok (NULL, delim1);
  7500. i = i + 1;
  7501. }
  7502. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7503. //local Authorizations List Numbers
  7504. //n_localAuthorizations = i;
  7505. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7506. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7507. c= 0;
  7508. while(c < i) // i is CardList Number
  7509. {
  7510. //Search "IdToken"
  7511. memset(sstr ,0, sizeof(sstr) );
  7512. loc = strstr(CardList[c], "idTag");
  7513. int j = 0;
  7514. while (loc[3+strlen("idTag")+j] != '\"')
  7515. {
  7516. sstr[j] = loc[3+strlen("idTag")+j];
  7517. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7518. j++;
  7519. }
  7520. sstr[j] = '\0';
  7521. strcpy(idTagstr, sstr);
  7522. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7523. //Search "expiryDate"
  7524. memset(sstr ,0, sizeof(sstr) );
  7525. loc = strstr(CardList[c], "expiryDate");
  7526. j = 0;
  7527. if(loc != NULL)
  7528. {
  7529. while (loc[3+strlen("expiryDate")+j] != '\"')
  7530. {
  7531. sstr[j] = loc[3+strlen("expiryDate")+j];
  7532. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7533. j++;
  7534. }
  7535. sstr[j] = '\0';
  7536. strcpy(expiryDate, sstr);
  7537. }
  7538. else
  7539. {
  7540. strcpy(expiryDate, "");
  7541. }
  7542. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7543. //Search "parentIdTag"
  7544. memset(sstr ,0, sizeof(sstr) );
  7545. loc = strstr(CardList[c], "parentIdTag");
  7546. j = 0;
  7547. if(loc != NULL)
  7548. {
  7549. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7550. {
  7551. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7552. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7553. j++;
  7554. }
  7555. sstr[j] = '\0';
  7556. strcpy(parentIdTag, sstr);
  7557. }
  7558. else
  7559. {
  7560. strcpy(parentIdTag, "");
  7561. }
  7562. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7563. //Search "status"
  7564. memset(sstr ,0, sizeof(sstr) );
  7565. loc = strstr(CardList[c], "status");
  7566. j = 0;
  7567. while (loc[3+strlen("status")+j] != '\"')
  7568. {
  7569. sstr[j] = loc[3+strlen("status")+j];
  7570. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7571. j++;
  7572. }
  7573. sstr[j] = '\0';
  7574. strcpy(idTagstatus, sstr);
  7575. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7576. OCPP_getIdTag(idTagstr);
  7577. //OCPP_getIdTag("test"); For Test
  7578. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7579. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7580. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7581. {
  7582. //Local list full update
  7583. DEBUG_INFO("Local list full update.\n");
  7584. // update list
  7585. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7586. //DEBUG_INFO("Local list full update. 1\n");
  7587. //OCPP_get_TableAuthlocalAllData();
  7588. //DEBUG_INFO("Local list full update. 2\n");
  7589. }
  7590. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7591. {
  7592. #if 0
  7593. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7594. {
  7595. //OCPP_deleteIdTag(idTagstr);
  7596. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7597. }
  7598. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7599. {
  7600. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7601. }
  7602. #endif
  7603. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7604. }
  7605. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7606. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7607. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7608. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7609. c++;
  7610. }
  7611. }
  7612. else
  7613. {
  7614. //Check UpdateType
  7615. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7616. {
  7617. //Local list full update
  7618. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7619. OCPP_cleanLocalList();
  7620. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7621. goto end;
  7622. }
  7623. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7624. {
  7625. //Local list different update
  7626. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7627. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7628. goto end;
  7629. }
  7630. }
  7631. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7632. end:
  7633. sendSendLocalListConfirmation(uuid, comfirmstr);
  7634. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7635. return result;
  7636. }
  7637. #define MAX 200
  7638. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7639. {
  7640. mtrace();
  7641. int result = FAIL;
  7642. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7643. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7644. char chargingProfilePurposeStr[30]={0};
  7645. char chargingProfileKindStr[16]={0};
  7646. char recurrencyKindStr[10]={0};
  7647. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7648. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7649. int chargingSchedulePeriodCount = 0;
  7650. //int updateflag = FALSE;
  7651. char comfirmstr[20]={0};
  7652. int meet= FALSE;
  7653. char sstr[10]={0};
  7654. int c = 0;
  7655. char *loc;
  7656. FILE *fptr1;//, *fptr2;
  7657. //int lno=0;//, linectr = 0;
  7658. //int modifyflag = FALSE;
  7659. char filename[MAX]={0};
  7660. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7661. //int resultRename=0;
  7662. char rmFileCmd[50]={0};
  7663. char tempchargingProfilePurposeStr[30]={0};
  7664. char word[1600]={0};
  7665. int n_chargingProfile = 0;
  7666. //[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}}}]
  7667. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7668. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7669. //*********************connectorId***************************/
  7670. loc = strstr(payload, "connectorId");
  7671. c = 0;
  7672. memset(sstr ,0, sizeof(sstr) );
  7673. while (loc[strlen("connectorId")+2+c] != ',')
  7674. {
  7675. sstr[c] = loc[strlen("connectorId")+2+c];
  7676. c++;
  7677. }
  7678. sstr[c] = '\0';
  7679. connectorIdInt = atoi(sstr);
  7680. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7681. {
  7682. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7683. }
  7684. else
  7685. {
  7686. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7687. }
  7688. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7689. //*********************chargingProfileId***************************/
  7690. loc = strstr(payload, "chargingProfileId");
  7691. c = 0;
  7692. memset(sstr ,0, sizeof(sstr) );
  7693. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7694. {
  7695. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7696. c++;
  7697. }
  7698. sstr[c] = '\0';
  7699. chargingProfileIdInt = atoi(sstr);
  7700. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7701. {
  7702. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7703. }
  7704. else
  7705. {
  7706. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7707. }
  7708. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7709. //*********************transactionId***************************/
  7710. loc = strstr(payload, "transactionId");
  7711. if(loc != NULL)
  7712. {
  7713. c = 0;
  7714. memset(sstr ,0, sizeof(sstr) );
  7715. while (loc[strlen("transactionId")+2+c] != ',')
  7716. {
  7717. sstr[c] = loc[strlen("transactionId")+2+c];
  7718. c++;
  7719. }
  7720. sstr[c] = '\0';
  7721. transactionIdInt = atoi(sstr);
  7722. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7723. {
  7724. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7725. }
  7726. else
  7727. {
  7728. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7729. }
  7730. }
  7731. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7732. //*********************stackLevel***************************/
  7733. loc = strstr(payload, "stackLevel");
  7734. c = 0;
  7735. memset(sstr ,0, sizeof(sstr) );
  7736. while (loc[strlen("stackLevel")+2+c] != ',')
  7737. {
  7738. sstr[c] = loc[strlen("stackLevel")+2+c];
  7739. c++;
  7740. }
  7741. sstr[c] = '\0';
  7742. stackLevelInt = atoi(sstr);
  7743. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7744. {
  7745. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7746. }
  7747. else
  7748. {
  7749. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7750. }
  7751. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7752. //*********************chargingProfilePurpose***************************/
  7753. loc = strstr(payload, "chargingProfilePurpose");
  7754. c = 0;
  7755. memset(sstr ,0, sizeof(sstr) );
  7756. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7757. {
  7758. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7760. c++;
  7761. }
  7762. sstr[c] = '\0';
  7763. strcpy(chargingProfilePurposeStr,sstr);
  7764. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7765. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7766. {
  7767. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7768. }
  7769. else
  7770. {
  7771. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7772. }
  7773. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7774. //*********************chargingProfileKind***************************/
  7775. loc = strstr(payload, "chargingProfileKind");
  7776. c = 0;
  7777. memset(sstr ,0, sizeof(sstr) );
  7778. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7779. {
  7780. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7782. c++;
  7783. }
  7784. sstr[c] = '\0';
  7785. strcpy(chargingProfileKindStr,sstr);
  7786. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7787. {
  7788. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7789. }
  7790. else
  7791. {
  7792. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7793. }
  7794. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7795. //*********************recurrencyKind***************************/
  7796. loc = strstr(payload, "recurrencyKind");
  7797. if(loc != NULL)
  7798. {
  7799. c = 0;
  7800. memset(sstr ,0, sizeof(sstr) );
  7801. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7802. {
  7803. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7804. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7805. c++;
  7806. }
  7807. sstr[c] = '\0';
  7808. strcpy(recurrencyKindStr,sstr);
  7809. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7810. {
  7811. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7812. }
  7813. else
  7814. {
  7815. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7816. }
  7817. }
  7818. else
  7819. {
  7820. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7821. {
  7822. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7823. }
  7824. else
  7825. {
  7826. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7827. }
  7828. }
  7829. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7830. //*********************validFrom***************************/
  7831. loc = strstr(payload, "validFrom");
  7832. if(loc != NULL)
  7833. {
  7834. c = 0;
  7835. memset(sstr ,0, sizeof(sstr) );
  7836. while (loc[3+strlen("validFrom")+c] != '\"')
  7837. {
  7838. sstr[c] = loc[3+strlen("validFrom")+c];
  7839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7840. c++;
  7841. }
  7842. sstr[c] = '\0';
  7843. strcpy(validFromStr,sstr);
  7844. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7845. {
  7846. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7847. }
  7848. else
  7849. {
  7850. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7851. }
  7852. }
  7853. else
  7854. {
  7855. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7856. {
  7857. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7858. }
  7859. else
  7860. {
  7861. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7862. }
  7863. }
  7864. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7865. //*********************validTo***************************/
  7866. loc = strstr(payload, "validTo");
  7867. if(loc != NULL)
  7868. {
  7869. c = 0;
  7870. memset(sstr ,0, sizeof(sstr) );
  7871. while (loc[3+strlen("validTo")+c] != '\"')
  7872. {
  7873. sstr[c] = loc[3+strlen("validTo")+c];
  7874. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7875. c++;
  7876. }
  7877. sstr[c] = '\0';
  7878. strcpy(validToStr,sstr);
  7879. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7880. {
  7881. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7882. }
  7883. else
  7884. {
  7885. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7886. }
  7887. }
  7888. else
  7889. {
  7890. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7891. {
  7892. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7893. }
  7894. else
  7895. {
  7896. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7897. }
  7898. }
  7899. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7900. //*********************duration***************************/
  7901. loc = strstr(payload, "duration");
  7902. if(loc != NULL)
  7903. {
  7904. c = 0;
  7905. memset(sstr ,0, sizeof(sstr) );
  7906. while (loc[strlen("duration")+2+c] != ',')
  7907. {
  7908. sstr[c] = loc[strlen("duration")+2+c];
  7909. c++;
  7910. }
  7911. sstr[c] = '\0';
  7912. durationInt = atoi(sstr);
  7913. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7914. {
  7915. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7916. }
  7917. else
  7918. {
  7919. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7920. }
  7921. }
  7922. else
  7923. {
  7924. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7925. {
  7926. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7927. }
  7928. else
  7929. {
  7930. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7931. }
  7932. }
  7933. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7934. //*********************startSchedule***************************/
  7935. loc = strstr(payload, "startSchedule");
  7936. if(loc != NULL)
  7937. {
  7938. c = 0;
  7939. memset(sstr ,0, sizeof(sstr) );
  7940. while (loc[3+strlen("startSchedule")+c] != '\"')
  7941. {
  7942. sstr[c] = loc[3+strlen("startSchedule")+c];
  7943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7944. c++;
  7945. }
  7946. sstr[c] = '\0';
  7947. strcpy(startScheduleStr,sstr);
  7948. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7949. {
  7950. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7951. }
  7952. else
  7953. {
  7954. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7955. }
  7956. }
  7957. else
  7958. {
  7959. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7960. {
  7961. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7962. }
  7963. else
  7964. {
  7965. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7966. }
  7967. }
  7968. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7969. //*********************chargingRateUnit***************************/
  7970. loc = strstr(payload, "chargingRateUnit");
  7971. if(loc != NULL)
  7972. {
  7973. c = 0;
  7974. memset(sstr ,0, sizeof(sstr) );
  7975. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7976. {
  7977. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7979. c++;
  7980. }
  7981. sstr[c] = '\0';
  7982. strcpy(chargingRateUnitStr,sstr);
  7983. #if 0
  7984. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7985. {
  7986. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7987. goto end;
  7988. }
  7989. #endif
  7990. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7991. {
  7992. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7993. }
  7994. else
  7995. {
  7996. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7997. }
  7998. }
  7999. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8000. //****************chargingSchedulePeriod count start*******************/
  8001. int what_len = strlen("startPeriod");
  8002. char tempChargingProfile[1000]={0};
  8003. strcpy(tempChargingProfile,(const char*)payload);
  8004. char *where = tempChargingProfile;
  8005. if (what_len)
  8006. {
  8007. while ((where = strstr(where, "startPeriod"))) {
  8008. where += what_len;
  8009. chargingSchedulePeriodCount++;
  8010. }
  8011. }
  8012. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8013. {
  8014. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8015. goto end;
  8016. }
  8017. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8018. //where = payload;
  8019. int templength = 0;
  8020. //int searchstart = 0;
  8021. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8022. {
  8023. //****************startPeriod*******************/
  8024. c=0;
  8025. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8026. memset(sstr ,0, sizeof(sstr) );
  8027. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8028. {
  8029. sstr[c] = loc[strlen("startPeriod")+2+c];
  8030. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8031. c++;
  8032. }
  8033. sstr[c] = '\0';
  8034. startPeriodInt[periodNums] = atoi(sstr);
  8035. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8036. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8037. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8038. {
  8039. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8040. }
  8041. else
  8042. {
  8043. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8044. }
  8045. templength = strlen("startPeriod")+2+c;
  8046. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8047. //****************limit*******************/
  8048. c=0;
  8049. loc = strstr(tempChargingProfile + templength, "limit");
  8050. memset(sstr ,0, sizeof(sstr) );
  8051. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8052. {
  8053. sstr[c] = loc[strlen("limit")+2+c];
  8054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8055. c++;
  8056. }
  8057. sstr[c] = '\0';
  8058. limitflaot[periodNums] = atof(sstr);
  8059. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8060. {
  8061. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8062. }
  8063. else
  8064. {
  8065. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8066. }
  8067. templength = templength + strlen("limit")+2+c;
  8068. //****************numberPhases*******************/
  8069. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8070. if(loc != NULL)
  8071. {
  8072. c=0;
  8073. memset(sstr ,0, sizeof(sstr) );
  8074. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8075. {
  8076. sstr[c] = loc[strlen("numberPhases")+2+c];
  8077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8078. c++;
  8079. }
  8080. sstr[c] = '\0';
  8081. numberPhasesInt[periodNums] = atoi(sstr);
  8082. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8083. {
  8084. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8085. }
  8086. else
  8087. {
  8088. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8089. }
  8090. templength = templength + strlen("numberPhases")+2+c;
  8091. }
  8092. //where = loc;
  8093. }
  8094. //****************chargingSchedulePeriod count end*******************/
  8095. //*********************minChargingRate***************************/
  8096. loc = strstr(payload, "minChargingRate");
  8097. if(loc != NULL)
  8098. {
  8099. c = 0;
  8100. memset(sstr ,0, sizeof(sstr) );
  8101. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8102. {
  8103. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8104. c++;
  8105. }
  8106. sstr[c] = '\0';
  8107. minChargingRateFloat = atof(sstr);
  8108. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8109. {
  8110. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8111. }
  8112. else
  8113. {
  8114. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8115. }
  8116. }
  8117. else
  8118. {
  8119. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8120. {
  8121. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8122. }
  8123. else
  8124. {
  8125. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8126. }
  8127. }
  8128. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8129. {
  8130. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8131. if(connectorIdInt != 0)
  8132. {
  8133. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8134. goto end;
  8135. }
  8136. strcpy(filename, ChargePointMaxProfile_JSON );
  8137. fptr1 = fopen(filename, "r");
  8138. if (!fptr1)
  8139. {
  8140. //file not exist
  8141. DEBUG_INFO("Unable to open the input file!!\n");
  8142. fptr1 = fopen(filename, "w+");
  8143. }
  8144. else
  8145. {
  8146. //Check Charging Profile Count
  8147. while(fscanf(fptr1, "%s", word) != EOF)
  8148. {
  8149. //DEBUG_INFO("word=%s\n",word);
  8150. if(strstr(word, "chargingProfileId")!= NULL)
  8151. {
  8152. //DEBUG_INFO("test chargingProfileId \n");
  8153. n_chargingProfile = n_chargingProfile + 1;
  8154. //DEBUG_INFO("chargingProfileId Found\n");
  8155. }
  8156. }
  8157. }
  8158. fclose(fptr1);
  8159. }
  8160. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8161. {
  8162. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8163. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8164. {
  8165. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8166. goto end;
  8167. }
  8168. #if 0
  8169. switch(connectorIdInt)
  8170. {
  8171. case 0:
  8172. strcpy(filename, TxDefaultProfile_0_JSON );
  8173. break;
  8174. case 1:
  8175. strcpy(filename, TxDefaultProfile_1_JSON );
  8176. break;
  8177. case 2:
  8178. strcpy(filename, TxDefaultProfile_2_JSON );
  8179. break;
  8180. default:
  8181. strcpy(filename, TxDefaultProfile_0_JSON );
  8182. break;
  8183. }
  8184. #endif
  8185. memset(filename, 0, sizeof filename);
  8186. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8187. fptr1 = fopen(filename, "r");
  8188. if (!fptr1)
  8189. {
  8190. //file not exist
  8191. //DEBUG_INFO("Unable to open the input file!!\n");
  8192. fptr1 = fopen(filename, "w+");
  8193. }
  8194. else
  8195. {
  8196. //Check Charging Profile Count
  8197. while(fscanf(fptr1, "%s", word) != EOF)
  8198. {
  8199. //DEBUG_INFO("word=%s\n",word);
  8200. if(strstr(word, "chargingProfileId")!= NULL)
  8201. {
  8202. //DEBUG_INFO("test chargingProfileId \n");
  8203. n_chargingProfile = n_chargingProfile + 1;
  8204. //DEBUG_INFO("chargingProfileId Found\n");
  8205. }
  8206. }
  8207. }
  8208. fclose(fptr1);
  8209. }
  8210. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8211. {
  8212. //printf("set chargingProfile 1-4\n");
  8213. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8214. //check Transaction active
  8215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8216. {
  8217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8218. {
  8219. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8220. {
  8221. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8222. {
  8223. meet = TRUE;
  8224. break;
  8225. }
  8226. }
  8227. }
  8228. }
  8229. for (int index = 0; index < CCS_QUANTITY; index++)
  8230. {
  8231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8232. {
  8233. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8234. {
  8235. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8236. {
  8237. meet = TRUE;
  8238. break;
  8239. }
  8240. }
  8241. }
  8242. }
  8243. for (int index = 0; index < GB_QUANTITY; index++)
  8244. {
  8245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8246. {
  8247. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8248. {
  8249. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8250. {
  8251. meet = TRUE;
  8252. break;
  8253. }
  8254. }
  8255. }
  8256. }
  8257. if(meet == FALSE)
  8258. {
  8259. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8260. goto end;
  8261. }
  8262. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8263. {
  8264. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8265. goto end;
  8266. }
  8267. #if 0
  8268. switch(connectorIdInt)
  8269. {
  8270. case 0:
  8271. break;
  8272. case 1:
  8273. strcpy(filename, TxProfile_1_JSON);
  8274. break;
  8275. case 2:
  8276. strcpy(filename, TxProfile_2_JSON);
  8277. break;
  8278. default:
  8279. strcpy(filename, TxProfile_1_JSON);
  8280. break;
  8281. }
  8282. #endif
  8283. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8284. fptr1 = fopen(filename, "r");
  8285. if (!fptr1)
  8286. {
  8287. //file not exist
  8288. DEBUG_INFO("Unable to open the input file!!\n");
  8289. fptr1 = fopen(filename, "w+");
  8290. }
  8291. else
  8292. {
  8293. //Check Charging Profile Count
  8294. while(fscanf(fptr1, "%s", word) != EOF)
  8295. {
  8296. //DEBUG_INFO("word=%s\n",word);
  8297. if(strstr(word, "chargingProfileId")!= NULL)
  8298. {
  8299. //DEBUG_INFO("test chargingProfileId \n");
  8300. n_chargingProfile = n_chargingProfile + 1;
  8301. //DEBUG_INFO("chargingProfileId Found\n");
  8302. }
  8303. }
  8304. }
  8305. fclose(fptr1);
  8306. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8307. }
  8308. // Check ChargeProfileMaxStackLevel
  8309. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8310. {
  8311. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8312. goto end;
  8313. }
  8314. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8315. {
  8316. int i = 0;
  8317. char fnametemp[200]={0};
  8318. n_chargingProfile = 0;
  8319. //Check ChargePointMaxProfile.json exit
  8320. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8321. {
  8322. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8323. //Check Charging Profile Count
  8324. while(fscanf(fptr1, "%s", word) != EOF)
  8325. {
  8326. //DEBUG_INFO("word=%s\n",word);
  8327. if(strstr(word, "chargingProfileId")!= NULL)
  8328. {
  8329. //DEBUG_INFO("test chargingProfileId \n");
  8330. n_chargingProfile = n_chargingProfile + 1;
  8331. i = i + 1;
  8332. //DEBUG_INFO("chargingProfileId Found\n");
  8333. }
  8334. memset(word, 0, sizeof word);
  8335. }
  8336. fclose(fptr1);
  8337. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8338. }
  8339. //Check TxDefaultProfile_0.json exit
  8340. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8341. {
  8342. i = 0;
  8343. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8344. //Check Charging Profile Count
  8345. while(fscanf(fptr1, "%s", word) != EOF)
  8346. {
  8347. //DEBUG_INFO("word=%s\n",word);
  8348. if(strstr(word, "chargingProfileId")!= NULL)
  8349. {
  8350. //DEBUG_INFO("test chargingProfileId \n");
  8351. n_chargingProfile = n_chargingProfile + 1;
  8352. i = i + 1;
  8353. //DEBUG_INFO("chargingProfileId Found\n");
  8354. }
  8355. memset(word, 0, sizeof word);
  8356. }
  8357. fclose(fptr1);
  8358. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8359. }
  8360. //Check TxDefaultProfile_%d.json
  8361. for(int j=1; j <= gunTotalNumber; j++)
  8362. {
  8363. memset(fnametemp, 0, sizeof fnametemp);
  8364. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8365. if((access(fnametemp,F_OK))!=-1)
  8366. {
  8367. i = 0;
  8368. fptr1 = fopen(fnametemp, "r");
  8369. //Check Charging Profile Count
  8370. while(fscanf(fptr1, "%s", word) != EOF)
  8371. {
  8372. //DEBUG_INFO("word=%s\n",word);
  8373. if(strstr(word, "chargingProfileId")!= NULL)
  8374. {
  8375. //DEBUG_INFO("test chargingProfileId \n");
  8376. n_chargingProfile = n_chargingProfile + 1;
  8377. i = i + 1;
  8378. //DEBUG_INFO("chargingProfileId Found\n");
  8379. }
  8380. memset(word, 0, sizeof word);
  8381. }
  8382. fclose(fptr1);
  8383. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8384. }
  8385. }
  8386. //Check TxProfile_%d.json
  8387. for(int j=1; j <= gunTotalNumber; j++)
  8388. {
  8389. memset(fnametemp, 0, sizeof fnametemp);
  8390. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8391. if((access(fnametemp,F_OK))!=-1)
  8392. {
  8393. i = 0;
  8394. fptr1 = fopen(fnametemp, "r");
  8395. //Check Charging Profile Count
  8396. while(fscanf(fptr1, "%s", word) != EOF)
  8397. {
  8398. //DEBUG_INFO("word=%s\n",word);
  8399. if(strstr(word, "chargingProfileId")!= NULL)
  8400. {
  8401. //DEBUG_INFO("test chargingProfileId \n");
  8402. n_chargingProfile = n_chargingProfile + 1;
  8403. i = i + 1;
  8404. //DEBUG_INFO("chargingProfileId Found\n");
  8405. }
  8406. memset(word, 0, sizeof word);
  8407. }
  8408. fclose(fptr1);
  8409. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8410. }
  8411. }
  8412. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8413. {
  8414. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8415. goto end;
  8416. }
  8417. }
  8418. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8419. //**********************************Write to File********************************************************/
  8420. FILE *infile;
  8421. FILE *outfile;
  8422. // open file for writing
  8423. infile = fopen (filename, "r");
  8424. outfile = fopen (tempfile, "w");
  8425. int d =0;
  8426. d = fgetc(infile);
  8427. //DEBUG_INFO("d:%d\n",d);
  8428. rewind(infile);
  8429. //*检测到文件结束标识返回1,否则返回0。*/
  8430. if(d == EOF)
  8431. {
  8432. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8433. fprintf(outfile,"%s\n",payload);
  8434. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8435. fclose(infile);
  8436. fclose(outfile);
  8437. sprintf(rmFileCmd,"rm -f %s",filename);
  8438. system(rmFileCmd);
  8439. rename(tempfile, filename);
  8440. #if 0
  8441. resultRename = rename(tempfile, filename);
  8442. if(resultRename == 0)
  8443. {
  8444. DEBUG_INFO("File chargingProfile renamed successfully");
  8445. }
  8446. else
  8447. {
  8448. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8449. }
  8450. #endif
  8451. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8452. //system(rmFileCmd);
  8453. }
  8454. else
  8455. {
  8456. char buf[1000]={0};
  8457. int ChargingProfileAdded = FALSE;
  8458. while (fgets(buf, sizeof(buf), infile) != NULL)
  8459. {
  8460. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8461. //*************************tempconnectorIdInt*********************************/
  8462. loc = strstr(buf, "connectorId");
  8463. c = 0;
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. while (loc[strlen("connectorId")+2+c] != ',')
  8466. {
  8467. sstr[c] = loc[strlen("connectorId")+2+c];
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. tempconnectorIdInt = atoi(sstr);
  8472. //*************************tempchargingProfileIdInt*********************************/
  8473. loc = strstr(buf, "chargingProfileId");
  8474. c = 0;
  8475. memset(sstr ,0, sizeof(sstr) );
  8476. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8477. {
  8478. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. tempchargingProfileIdInt = atoi(sstr);
  8483. //*************************tempstackLevelInt*********************************/
  8484. loc = strstr(buf, "stackLevel");
  8485. c = 0;
  8486. memset(sstr ,0, sizeof(sstr) );
  8487. while (loc[strlen("stackLevel")+2+c] != ',')
  8488. {
  8489. sstr[c] = loc[strlen("stackLevel")+2+c];
  8490. c++;
  8491. }
  8492. sstr[c] = '\0';
  8493. tempstackLevelInt = atoi(sstr);
  8494. //*************************tempchargingProfilePurposeStr*********************************/
  8495. loc = strstr(payload, "chargingProfilePurpose");
  8496. c = 0;
  8497. memset(sstr ,0, sizeof(sstr) );
  8498. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8499. {
  8500. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8502. c++;
  8503. }
  8504. sstr[c] = '\0';
  8505. strcpy(tempchargingProfilePurposeStr,sstr);
  8506. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8507. {
  8508. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8509. {
  8510. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8511. if(ChargingProfileAdded == FALSE)
  8512. {
  8513. fprintf(outfile,"%s\n",payload);
  8514. ChargingProfileAdded = TRUE;
  8515. }
  8516. }
  8517. else
  8518. {
  8519. if(tempstackLevelInt < stackLevelInt)
  8520. {
  8521. if(ChargingProfileAdded == FALSE)
  8522. {
  8523. fprintf(outfile,"%s\n",payload);
  8524. ChargingProfileAdded = TRUE;
  8525. fprintf(outfile,"%s\n",buf);
  8526. }
  8527. else
  8528. {
  8529. fprintf(outfile,"%s\n",buf);
  8530. }
  8531. }
  8532. else
  8533. {
  8534. if(ChargingProfileAdded == FALSE)
  8535. {
  8536. fprintf(outfile,"%s\n",buf);
  8537. fprintf(outfile,"%s\n",payload);
  8538. ChargingProfileAdded = TRUE;
  8539. }
  8540. else
  8541. {
  8542. fprintf(outfile,"%s\n",buf);
  8543. }
  8544. }
  8545. }
  8546. }
  8547. else
  8548. {
  8549. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8550. {
  8551. if(ChargingProfileAdded == FALSE)
  8552. {
  8553. fprintf(outfile,"%s\n",payload);
  8554. ChargingProfileAdded = TRUE;
  8555. fprintf(outfile,"%s\n",buf);
  8556. }
  8557. else
  8558. {
  8559. fprintf(outfile,"%s\n",buf);
  8560. }
  8561. }
  8562. else if(tempstackLevelInt < stackLevelInt)
  8563. {
  8564. if(ChargingProfileAdded == FALSE)
  8565. {
  8566. fprintf(outfile,"%s\n",payload);
  8567. ChargingProfileAdded = TRUE;
  8568. fprintf(outfile,"%s\n",buf);
  8569. }
  8570. else
  8571. {
  8572. fprintf(outfile,"%s\n",buf);
  8573. }
  8574. }
  8575. else
  8576. {
  8577. if(ChargingProfileAdded == FALSE)
  8578. {
  8579. fprintf(outfile,"%s\n",buf);
  8580. fprintf(outfile,"%s\n",payload);
  8581. ChargingProfileAdded = TRUE;
  8582. }
  8583. else
  8584. {
  8585. fprintf(outfile,"%s\n",buf);
  8586. }
  8587. }
  8588. }
  8589. } // end of while loop
  8590. fclose(infile);
  8591. fclose(outfile);
  8592. sprintf(rmFileCmd,"rm -f %s",filename);
  8593. system(rmFileCmd);
  8594. rename(tempfile, filename);
  8595. #if 0
  8596. resultRename = rename(tempfile, filename);
  8597. if(resultRename == 0)
  8598. {
  8599. DEBUG_INFO("File chargingProfile renamed successfully");
  8600. }
  8601. else
  8602. {
  8603. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8604. }
  8605. #endif
  8606. result = TRUE;
  8607. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8608. }
  8609. end:
  8610. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8611. return result;
  8612. return result;
  8613. }
  8614. int handleTriggerMessageRequest(char *uuid, char *payload)
  8615. {
  8616. mtrace();
  8617. int result = FAIL;
  8618. int connectorIdIsNULL = FALSE;
  8619. int connectorIdInt =0;
  8620. char sstr[40]={0};
  8621. char requestedMessagestr[40]={0};
  8622. char comfirmstr[20]={0};
  8623. int c = 0;
  8624. char *loc;
  8625. DEBUG_INFO("handleTriggerMessageRequest\n");
  8626. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8627. c = 0;
  8628. loc = strstr(payload, "requestedMessage");
  8629. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8630. {
  8631. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8632. c++;
  8633. }
  8634. sstr[c] = '\0';
  8635. strcpy(requestedMessagestr, sstr);
  8636. c = 0;
  8637. loc = strstr(payload, "connectorId");
  8638. if(loc == NULL)
  8639. {
  8640. connectorIdIsNULL = TRUE;
  8641. }
  8642. else
  8643. {
  8644. memset(sstr ,0, sizeof(sstr) );
  8645. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8646. {
  8647. sstr[c] = loc[strlen("connectorId")+2+c];
  8648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8649. c++;
  8650. }
  8651. sstr[c] = '\0';
  8652. connectorIdInt = atoi(sstr);
  8653. }
  8654. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8655. {
  8656. //connectorIdInt = json_object_get_int(connectorId);
  8657. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8658. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8659. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8660. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8661. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8662. }
  8663. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8664. {
  8665. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8666. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8667. return TRUE;
  8668. }
  8669. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8670. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8671. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8672. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8673. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8674. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8675. {
  8676. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8677. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8678. return TRUE;
  8679. }
  8680. else
  8681. {
  8682. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8683. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8684. }
  8685. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8686. {
  8687. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8688. {
  8689. FirmwareStatusNotificationStatus = 3;
  8690. }
  8691. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8692. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8693. }
  8694. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8695. {
  8696. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8697. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8698. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8699. }
  8700. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8701. {
  8702. sendBootNotificationRequest();
  8703. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8704. }
  8705. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8706. {
  8707. sendHeartbeatRequest(connectorIdInt);
  8708. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8709. }
  8710. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8711. {
  8712. if(connectorIdIsNULL == FALSE)
  8713. {
  8714. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8715. {
  8716. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8717. sendMeterValuesRequest(connectorIdInt -1);
  8718. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8719. }
  8720. }
  8721. else
  8722. {
  8723. for(int idx=0;idx< gunTotalNumber;idx++)
  8724. {
  8725. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8726. sendMeterValuesRequest(idx);
  8727. }
  8728. }
  8729. }
  8730. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8731. {
  8732. if(connectorIdIsNULL == FALSE)
  8733. {
  8734. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8735. {
  8736. sendStatusNotificationRequest(connectorIdInt -1);
  8737. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8738. }
  8739. }
  8740. else
  8741. {
  8742. for(int idx=0;idx< gunTotalNumber;idx++)
  8743. sendStatusNotificationRequest(idx);
  8744. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8745. }
  8746. }
  8747. return result;
  8748. }
  8749. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8750. {
  8751. mtrace();
  8752. int result = FAIL;
  8753. char sstr[6]={0};
  8754. int connectorIdInt =0;
  8755. char comfirmstr[20]={0};
  8756. int c = 0;
  8757. char *loc;
  8758. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8759. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8760. c = 0;
  8761. loc = strstr(payload, "connectorId");
  8762. memset(sstr ,0, sizeof(sstr) );
  8763. while (loc[strlen("connectorId")+2+c] != '}')
  8764. {
  8765. sstr[c] = loc[strlen("connectorId")+2+c];
  8766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8767. c++;
  8768. }
  8769. sstr[c] = '\0';
  8770. connectorIdInt = atoi(sstr);
  8771. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8772. if(gunTotalNumber == 0)
  8773. {
  8774. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8775. goto end;
  8776. }
  8777. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8778. {
  8779. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8780. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8781. goto end;
  8782. }
  8783. else
  8784. {
  8785. //check Transaction active
  8786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8787. {
  8788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8789. {
  8790. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8791. {
  8792. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8793. }
  8794. }
  8795. for (int index = 0; index < CCS_QUANTITY; index++)
  8796. {
  8797. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8798. {
  8799. //stop Transaction
  8800. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8801. }
  8802. }
  8803. for (int index = 0; index < GB_QUANTITY; index++)
  8804. {
  8805. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8806. {
  8807. //stop Transaction
  8808. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8809. }
  8810. }
  8811. }
  8812. else
  8813. {
  8814. for (int index = 0; index < AC_QUANTITY; index++)
  8815. {
  8816. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8817. {
  8818. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8819. }
  8820. }
  8821. }// END FOR AC ELSE
  8822. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8823. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8824. result = TRUE;
  8825. return result;
  8826. }
  8827. end:
  8828. //json_object_put(obj); --- remove temporally
  8829. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8830. return result;
  8831. }
  8832. static char UpdateFirmwarepayloadData[300]={0};
  8833. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8834. {
  8835. mtrace();
  8836. int result = FAIL;
  8837. pthread_t t;
  8838. sendUpdateFirmwareConfirmation(uuid);
  8839. memset(UpdateFirmwarepayloadData, 0, 300);
  8840. strcpy(UpdateFirmwarepayloadData, payload);
  8841. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8842. ////pthread_join(t, NULL); //
  8843. //pthread_detach(t);
  8844. //sendUpdateFirmwareConfirmation(uuid);
  8845. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8846. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8847. return result;
  8848. }
  8849. void *UpdateFirmwareProcess(void *data)
  8850. {
  8851. pthread_detach(pthread_self());
  8852. mtrace();
  8853. int retriesInt =0, retryIntervalInt=0;
  8854. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8855. int port=0;
  8856. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8857. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8858. //char comfirmstr[20];
  8859. int isSuccess = 0;
  8860. char ftpbuf[200];
  8861. char temp[100];
  8862. char * pch;
  8863. int retriesISNULL=FALSE;
  8864. int retryInterval=FALSE;
  8865. int c = 0;
  8866. //int i = 0;
  8867. char *loc;
  8868. char sstr[300]={ 0 };
  8869. char str[300]={ 0 };
  8870. //char *str = (char*) data; // ? ?輸入資 ?
  8871. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8872. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8873. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8874. //***************location **************/
  8875. loc = strstr(str, "location");
  8876. memset(sstr ,0, sizeof(sstr) );
  8877. c = 0;
  8878. while (loc[3+strlen("location")+c] != '\"')
  8879. {
  8880. sstr[c] = loc[3+strlen("location")+c];
  8881. c++;
  8882. }
  8883. sstr[c] = '\0';
  8884. strcpy(locationstr, sstr);
  8885. //***************retries**************/
  8886. c = 0;
  8887. loc = strstr(str, "retries");
  8888. if(loc == NULL)
  8889. {
  8890. retriesISNULL=TRUE;
  8891. }
  8892. else
  8893. {
  8894. memset(sstr ,0, sizeof(sstr) );
  8895. while (loc[strlen("retries")+2+c] != ',')
  8896. {
  8897. sstr[c] = loc[strlen("retries")+2+c];
  8898. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8899. c++;
  8900. }
  8901. sstr[c] = '\0';
  8902. }
  8903. if(retriesISNULL == FALSE)
  8904. {
  8905. retriesInt = atoi(sstr);
  8906. }
  8907. //***************retrieveDate **************/
  8908. loc = strstr(str, "retrieveDate");
  8909. memset(sstr ,0, sizeof(sstr) );
  8910. c = 0;
  8911. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8912. {
  8913. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8914. c++;
  8915. }
  8916. sstr[c] = '\0';
  8917. strcpy(retrieveDatestr, sstr);
  8918. //***************retryInterval **************/
  8919. c = 0;
  8920. loc = strstr(str, "retryInterval");
  8921. memset(sstr ,0, sizeof(sstr) );
  8922. if(loc == NULL)
  8923. {
  8924. retryInterval=TRUE;
  8925. }
  8926. else
  8927. {
  8928. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8929. {
  8930. sstr[c] = loc[strlen("retryInterval")+2+c];
  8931. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8932. c++;
  8933. }
  8934. sstr[c] = '\0';
  8935. }
  8936. if(retryInterval==FALSE)
  8937. {
  8938. retryIntervalInt = atoi(sstr);
  8939. }
  8940. memset(ftppath, 0, sizeof(ftppath));
  8941. memset(path, 0, sizeof(path));
  8942. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8943. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8944. if(strncmp(locationstr,"http", 4) == 0)
  8945. {
  8946. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8947. protocol, host, path);
  8948. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8949. // protocol, user, password, host, path);
  8950. sprintf(ftppath,"/%s", path);
  8951. //DEBUG_INFO("protocol =%s\n",protocol);
  8952. //DEBUG_INFO("host =%s\n",host);
  8953. //DEBUG_INFO("path =%s\n",path);
  8954. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8955. int ftppathlen=strlen(ftppath);
  8956. int i=1;
  8957. char filenametemp[50];
  8958. while(i < ftppathlen)
  8959. {
  8960. int len=ftppathlen-i;
  8961. if(ftppath[len]== 47) // '/' ascll code: 47
  8962. {
  8963. DEBUG_INFO("compare '/' all right\n");
  8964. break;
  8965. }
  8966. i=i+1;
  8967. }
  8968. memset(filenametemp, 0, sizeof(filenametemp));
  8969. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8970. filenametemp[i+1] = 0;
  8971. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8972. do{
  8973. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8974. sleep(retryIntervalInt);
  8975. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8976. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8977. if(!isSuccess)
  8978. {
  8979. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8980. }
  8981. else
  8982. {
  8983. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8984. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8985. isUpdateRequest = TRUE;
  8986. }
  8987. }
  8988. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8989. {
  8990. memset(ftpbuf, 0, sizeof(ftpbuf));
  8991. memset(temp, 0, sizeof(temp));
  8992. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8993. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8994. int ftppathlen=strlen(ftpbuf);
  8995. int i=1;
  8996. char filenametemp[50];
  8997. while(i < ftppathlen)
  8998. {
  8999. int len=ftppathlen-i;
  9000. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9001. {
  9002. DEBUG_INFO(" compare '/' all right\n");
  9003. break;
  9004. }
  9005. i=i+1;
  9006. }
  9007. memset(filenametemp, 0, sizeof(filenametemp));
  9008. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9009. filenametemp[i+1] = 0;
  9010. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9011. pch=strchr(temp,'@');
  9012. if(pch==NULL)
  9013. {
  9014. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9015. protocol, host, &port, path);
  9016. strcpy(user,"anonymous");
  9017. strcpy(password,"");
  9018. }
  9019. else
  9020. {
  9021. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9022. protocol, user, password, host, &port, path);
  9023. }
  9024. sscanf(host,"%[^/]%s",host1, path1);
  9025. sprintf(ftppath,"%s", path1);
  9026. //DEBUG_INFO("protocol =%s\n",protocol);
  9027. //DEBUG_INFO("user =%s\n",user);
  9028. //DEBUG_INFO("password =%s\n",password);
  9029. //DEBUG_INFO("host1 =%s\n",host1);
  9030. //DEBUG_INFO("port =%d\n",port);
  9031. //DEBUG_INFO("path1 =%s\n",path1);
  9032. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9033. //ftpFile(host, user, password, port, ftppath, fname);
  9034. //download firmware pthred
  9035. if(port == 0)
  9036. {
  9037. port = 21;
  9038. }
  9039. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9040. do{
  9041. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9042. sleep(retryIntervalInt);
  9043. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9044. if(!isSuccess)
  9045. {
  9046. //BulldogUtil.sleepMs(interval*1000);
  9047. DEBUG_INFO("Update firmware request and download file fail.\n");
  9048. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9049. }
  9050. else
  9051. {
  9052. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9053. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9054. isUpdateRequest = TRUE;
  9055. }
  9056. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9057. }
  9058. else
  9059. {
  9060. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9061. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9062. }
  9063. pthread_exit(NULL);
  9064. }
  9065. //==========================================
  9066. // Handle server response routine
  9067. //==========================================
  9068. void handleAuthorizeResponse(char *payload, int gun_index)
  9069. {
  9070. mtrace();
  9071. char expiryDatestr[30]={0};
  9072. char parentIdTagstr[20]={0};
  9073. char statusstr[20]={0};
  9074. char expiryDatestrtemp[30]={0};
  9075. char parentIdTagstrtemp[20]={0};
  9076. char IdTagstrtemp[20]={0};
  9077. char statusstrtemp[20]={0};
  9078. int expiryDateISNULL=FALSE;
  9079. int parentIdTagISNULL=FALSE;
  9080. char sstr[160]={ 0 };
  9081. char* filename = AuthorizationCache_JSON;
  9082. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9083. int c = 0;
  9084. char *loc;
  9085. int resultRename=0;
  9086. int responseIdTagInfoAsZero= 0;
  9087. char rmFileCmd[50]={0};
  9088. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9089. //***********expiryDate*************/
  9090. loc = strstr(payload, "expiryDate");
  9091. memset(sstr ,0, sizeof(sstr) );
  9092. c = 0;
  9093. if(loc == NULL)
  9094. {
  9095. expiryDateISNULL = TRUE;
  9096. }
  9097. else
  9098. {
  9099. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9100. {
  9101. sstr[c] = loc[3+strlen("expiryDate")+c];
  9102. c++;
  9103. }
  9104. sstr[c] = '\0';
  9105. strcpy(expiryDatestr, sstr);
  9106. }
  9107. //***********parentIdTag*************/
  9108. loc = strstr(payload, "parentIdTag");
  9109. memset(sstr ,0, sizeof(sstr) );
  9110. c = 0;
  9111. if(loc == NULL)
  9112. {
  9113. parentIdTagISNULL = TRUE;
  9114. }
  9115. else
  9116. {
  9117. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9118. {
  9119. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9120. c++;
  9121. }
  9122. sstr[c] = '\0';
  9123. strcpy(parentIdTagstr, sstr);
  9124. }
  9125. //***********status*************/
  9126. loc = strstr(payload, "status");
  9127. memset(sstr ,0, sizeof(sstr) );
  9128. c = 0;
  9129. while (loc[3+strlen("status")+c] != '\"')
  9130. {
  9131. sstr[c] = loc[3+strlen("status")+c];
  9132. c++;
  9133. }
  9134. sstr[c] = '\0';
  9135. strcpy(statusstr, sstr);
  9136. if(expiryDateISNULL == FALSE)
  9137. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9138. if(parentIdTagISNULL == FALSE)
  9139. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9141. //Update idTag information to authorization cache if supproted
  9142. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9143. {
  9144. if((access(filename,F_OK))!=-1)
  9145. {
  9146. printf("AuthorizationCache exist.\n");
  9147. }
  9148. else
  9149. {
  9150. printf("AuthorizationCache not exist\n");
  9151. FILE *log = fopen(filename, "w+");
  9152. if(log == NULL)
  9153. {
  9154. printf("log is NULL\n");
  9155. goto out;
  9156. }
  9157. else
  9158. {
  9159. fclose(log);
  9160. }
  9161. }
  9162. FILE *infile;
  9163. FILE *outfile;
  9164. // open file for writing
  9165. infile = fopen (filename, "r");
  9166. outfile = fopen (tempfile, "w");
  9167. //*检测到文件结束标识返回1,否则返回0。*/
  9168. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9169. int c;
  9170. c = fgetc(infile);
  9171. //DEBUG_INFO("c:%d\n",c);
  9172. rewind(infile);
  9173. if(c == EOF)
  9174. {
  9175. DEBUG_INFO("Orignal File is NULL\n");
  9176. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9177. {
  9178. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9179. }
  9180. else
  9181. {
  9182. strcpy(expiryDatestrtemp, "");
  9183. }
  9184. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9185. {
  9186. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9187. }
  9188. else
  9189. {
  9190. //write Authorize IdTag
  9191. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9192. }
  9193. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9194. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9195. fclose(infile);
  9196. fclose(outfile);
  9197. sprintf(rmFileCmd,"rm -f %s",filename);
  9198. system(rmFileCmd);
  9199. resultRename = rename(tempfile, filename);
  9200. if(resultRename == 0)
  9201. {
  9202. printf("File renamed successfully");
  9203. }
  9204. else
  9205. {
  9206. printf("Error: unable to rename the file");
  9207. }
  9208. }
  9209. else
  9210. {
  9211. char buf[160]={0};
  9212. while (fgets(buf, sizeof(buf), infile) != NULL)
  9213. {
  9214. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9215. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9216. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9217. memset(statusstr, 0, sizeof(statusstrtemp));
  9218. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9219. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9220. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9221. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9222. //------------------IdTag-----------------------
  9223. loc = strstr(buf, "idTag");
  9224. memset(sstr ,0, sizeof(sstr) );
  9225. c = 0;
  9226. while (loc[3+strlen("idTag")+c] != '\"')
  9227. {
  9228. sstr[c] = loc[3+strlen("idTag")+c];
  9229. c++;
  9230. }
  9231. sstr[c] = '\0';
  9232. strcpy(IdTagstrtemp,sstr);
  9233. //*********************expiryDate***************/
  9234. loc = strstr(buf, "expiryDate");
  9235. memset(sstr ,0, sizeof(sstr) );
  9236. c = 0;
  9237. while (loc[3+strlen("expiryDate")+c] != '\"')
  9238. {
  9239. sstr[c] = loc[3+strlen("expiryDate")+c];
  9240. c++;
  9241. }
  9242. sstr[c] = '\0';
  9243. strcpy(expiryDatestr,sstr);
  9244. //*********************parentIdTag***************/
  9245. loc = strstr(buf, "parentIdTag");
  9246. memset(sstr ,0, sizeof(sstr) );
  9247. c = 0;
  9248. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9249. {
  9250. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9251. c++;
  9252. }
  9253. sstr[c] = '\0';
  9254. strcpy(parentIdTagstr,sstr);
  9255. //*********************status***************/
  9256. loc = strstr(buf, "status");
  9257. memset(sstr ,0, sizeof(sstr) );
  9258. c = 0;
  9259. while (loc[3+strlen("status")+c] != '\"')
  9260. {
  9261. sstr[c] = loc[3+strlen("status")+c];
  9262. c++;
  9263. }
  9264. sstr[c] = '\0';
  9265. strcpy(statusstr,sstr);
  9266. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9267. {
  9268. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9269. responseIdTagInfoAsZero = 1;
  9270. }
  9271. else
  9272. {
  9273. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9274. }
  9275. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9276. {
  9277. //modify item
  9278. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9279. {
  9280. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9281. }
  9282. else
  9283. {
  9284. strcpy(expiryDatestrtemp, "");
  9285. }
  9286. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9287. {
  9288. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9289. }
  9290. else
  9291. {
  9292. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9293. }
  9294. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9295. }
  9296. else
  9297. {
  9298. //wrie original item
  9299. strcpy(expiryDatestrtemp, expiryDatestr);
  9300. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9301. strcpy(statusstrtemp, statusstr);
  9302. }
  9303. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9304. }
  9305. fclose(infile);
  9306. fclose(outfile);
  9307. sprintf(rmFileCmd,"rm -f %s",filename);
  9308. system(rmFileCmd);
  9309. resultRename = rename(tempfile, filename);
  9310. if(resultRename == 0)
  9311. {
  9312. DEBUG_INFO("File renamed successfully");
  9313. }
  9314. else
  9315. {
  9316. DEBUG_INFO("Error: unable to rename the file");
  9317. }
  9318. }
  9319. }
  9320. out:
  9321. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9322. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9323. authorizeRetryTimes = 0;
  9324. }
  9325. void handleBootNotificationResponse(char *payload, int gun_index)
  9326. {
  9327. mtrace();
  9328. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9329. char statusStr[12]={0};
  9330. char currentTimeStr[30]={0};
  9331. char *loc;
  9332. int intervalInt = 0;
  9333. int c = 0;
  9334. //double diff_t;
  9335. struct tm tp;
  9336. char buf[28]={0};
  9337. char timebuf[50]={0};
  9338. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9339. //*** interval ****/
  9340. c = 0;
  9341. loc = strstr(payload, "interval");
  9342. //printf("loc=%s\n",loc);
  9343. memset(sstr ,0, sizeof(sstr) );
  9344. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9345. {
  9346. sstr[c] = loc[strlen("interval")+2+c];
  9347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9348. c++;
  9349. }
  9350. sstr[c] = '\0';
  9351. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9352. intervalInt = atoi(sstr);
  9353. //***status ****/
  9354. loc = strstr(payload, "status");
  9355. memset(sstr ,0, sizeof(sstr) );
  9356. c = 0;
  9357. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9358. {
  9359. sstr[c] = loc[3+strlen("status")+c];
  9360. c++;
  9361. }
  9362. sstr[c] = '\0';
  9363. strcpy(statusStr, sstr);
  9364. //***currentTime ****/
  9365. loc = strstr(payload, "currentTime");
  9366. //printf("loc=%s\n",loc);
  9367. memset(sstr ,0, sizeof(sstr) );
  9368. c = 0;
  9369. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9370. {
  9371. sstr[c] = loc[3+strlen("currentTime")+c];
  9372. c++;
  9373. }
  9374. sstr[c] = '\0';
  9375. strcpy(currentTimeStr, sstr);
  9376. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9377. HeartBeatWaitTime = BootNotificationInterval;
  9378. clientTime.Heartbeat=time((time_t*)NULL);
  9379. //write back to ShmOCPP16Data->BootNotification
  9380. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9381. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9382. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9383. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9384. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9385. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9386. {
  9387. server_sign = TRUE;
  9388. server_pending =FALSE;
  9389. }
  9390. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9391. {
  9392. server_pending = TRUE;
  9393. }
  9394. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9395. tp.tm_isdst = -1;
  9396. //time_t utc = mktime(&tp);
  9397. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9398. memset(timebuf, 0, sizeof timebuf);
  9399. sprintf(timebuf,"date -s '%s'",buf);
  9400. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9401. system(timebuf);
  9402. //==============================================
  9403. // RTC sync
  9404. //==============================================
  9405. system("/sbin/hwclock -w --systohc");
  9406. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9407. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9408. }
  9409. void handleDataTransferResponse(char *payload, int gun_index)
  9410. {
  9411. char sstr[160]={0};//sstr[200]={ 0 };
  9412. int c = 0;
  9413. char *loc;
  9414. DEBUG_INFO("handleDataTransferResponse ...\n");
  9415. loc = strstr(payload, "status");
  9416. printf("loc=%s\n",loc);
  9417. c = 0;
  9418. while (loc[3+strlen("status")+c] != '\"')
  9419. {
  9420. sstr[c] = loc[3+strlen("status")+c];
  9421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9422. c++;
  9423. }
  9424. sstr[c] = '\0';
  9425. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9426. }
  9427. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9428. {
  9429. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9430. //struct json_object *obj;
  9431. // obj = json_tokener_parse(payload);
  9432. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9433. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9434. //No fields are defined.
  9435. }
  9436. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9437. {
  9438. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9439. //struct json_object *obj;
  9440. // obj = json_tokener_parse(payload);
  9441. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9442. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9443. //No fields are defined.
  9444. }
  9445. void handleHeartbeatResponse(char *payload, int gun_index)
  9446. {
  9447. mtrace();
  9448. //double diff_t;
  9449. struct tm tp;
  9450. char buf[28]={0};
  9451. char timebuf[50]={0};
  9452. char sstr[30]={ 0 };
  9453. int c = 0;
  9454. char *loc;
  9455. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9456. c = 0;
  9457. loc = strstr(payload, "currentTime");
  9458. memset(sstr ,0, sizeof(sstr) );
  9459. while (loc[3+strlen("currentTime")+c] != '\"')
  9460. {
  9461. sstr[c] = loc[3+strlen("currentTime")+c];
  9462. c++;
  9463. }
  9464. sstr[c] = '\0';
  9465. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9466. // #ifdef SystemLogMessage
  9467. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9468. // #endif
  9469. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9470. tp.tm_isdst = -1;
  9471. //time_t utc = mktime(&tp);
  9472. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9473. memset(timebuf, 0, sizeof timebuf);
  9474. sprintf(timebuf,"date -s '%s'",buf);
  9475. system(timebuf);
  9476. //==============================================
  9477. // RTC sync
  9478. //==============================================
  9479. system("/sbin/hwclock -w --systohc");
  9480. if(FirstHeartBeat == 0)
  9481. {
  9482. FirstHeartBeat = 1;
  9483. }
  9484. HeartBeatWithNOResponse = 0;
  9485. //--------Print Out HeartBeat log
  9486. {
  9487. double diff_t;
  9488. struct tm tp,tp1;
  9489. // BootNotification Receive Time
  9490. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9491. tp.tm_isdst = -1;
  9492. time_t BootNotificationReceiveTime = mktime(&tp);
  9493. //HeartBeat Receive Time
  9494. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9495. tp1.tm_isdst = -1;
  9496. time_t HeartBeatReceiveTime = mktime(&tp1);
  9497. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9498. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9499. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9500. {
  9501. HeartBeatCountPerHour = (int)diff_t / 3600;
  9502. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9503. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9504. }
  9505. }
  9506. }
  9507. void handleMeterValuesResponse(char *payload, int gun_index)
  9508. {
  9509. mtrace();
  9510. //struct json_object *obj;
  9511. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9512. //No fields are defined.
  9513. }
  9514. void handleStartTransactionResponse(char *payload, int gun_index)
  9515. {
  9516. mtrace();
  9517. char sstr[28]={ 0 };
  9518. int c = 0;
  9519. char *loc;
  9520. int transactionIdInt = 0;
  9521. FILE *outfile;
  9522. char data[100]={0};
  9523. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9524. DEBUG_INFO("handleStartTransactionResponse\n");
  9525. //****************expiryDate********************/
  9526. loc = strstr(payload, "expiryDate");
  9527. if(loc == NULL)
  9528. {
  9529. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9530. }
  9531. else
  9532. {
  9533. c = 0;
  9534. memset(sstr ,0, sizeof(sstr) );
  9535. while (loc[3+strlen("expiryDate")+c] != '\"')
  9536. {
  9537. sstr[c] = loc[3+strlen("expiryDate")+c];
  9538. c++;
  9539. }
  9540. sstr[c] = '\0';
  9541. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9542. }
  9543. //****************parentIdTag********************/
  9544. loc = strstr(payload, "parentIdTag");
  9545. if(loc == NULL)
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9548. }
  9549. else
  9550. {
  9551. c = 0;
  9552. memset(sstr ,0, sizeof(sstr) );
  9553. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9554. {
  9555. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9556. c++;
  9557. }
  9558. sstr[c] = '\0';
  9559. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9560. }
  9561. //****************status********************/
  9562. loc = strstr(payload, "status");
  9563. if(loc == NULL)
  9564. {
  9565. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9566. }
  9567. else
  9568. {
  9569. c = 0;
  9570. memset(sstr ,0, sizeof(sstr) );
  9571. while (loc[3+strlen("status")+c] != '\"')
  9572. {
  9573. sstr[c] = loc[3+strlen("status")+c];
  9574. c++;
  9575. }
  9576. sstr[c] = '\0';
  9577. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9578. }
  9579. //****************transactionId********************/
  9580. c=0;
  9581. loc = strstr(payload, "transactionId");
  9582. memset(sstr ,0, sizeof(sstr) );
  9583. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9584. {
  9585. sstr[c] = loc[strlen("transactionId")+2+c];
  9586. c++;
  9587. }
  9588. sstr[c] = '\0';
  9589. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9590. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9591. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9593. //-----------Start : write to the Queue TransactionId file -----------------//
  9594. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9595. {
  9596. //DEBUG_INFO("QueueTransactionId exist.\n");
  9597. }
  9598. else
  9599. {
  9600. //DEBUG_INFO("QueueTransactionId not exist\n");
  9601. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9602. if(log == NULL)
  9603. {
  9604. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9605. return ;
  9606. }
  9607. else
  9608. {
  9609. fclose(log);
  9610. }
  9611. }
  9612. // open file for writing
  9613. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9614. //DEBUG_INFO("data=%s\n",data);
  9615. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9616. fputs(data, outfile);
  9617. //fputs("\n", outfile);
  9618. fclose (outfile);
  9619. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9620. TransactionId[gun_index] = transactionIdInt;
  9621. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9622. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9623. #ifdef SystemLogMessage
  9624. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9625. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9626. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9627. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9628. #endif
  9629. }
  9630. void handleStatusNotificationResponse(char *payload, int gun_index)
  9631. {
  9632. mtrace();
  9633. printf("handleStatusNotificationResponse\n");
  9634. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9635. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9636. }
  9637. void handleStopTransactionnResponse(char *payload, int gun_index)
  9638. {
  9639. mtrace();
  9640. char sstr[30]={ 0 };
  9641. int c = 0;
  9642. char *loc;
  9643. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9644. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9645. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9646. loc = strstr(payload, "idTagInfo");
  9647. //***********************idTagInfo************************/
  9648. if(loc != NULL)
  9649. {
  9650. //***********************expiryDate************************/
  9651. loc = strstr(payload, "expiryDate");
  9652. if(loc != NULL)
  9653. {
  9654. memset(sstr ,0, sizeof(sstr) );
  9655. c = 0;
  9656. while (loc[3+strlen("expiryDate")+c] != '\"')
  9657. {
  9658. sstr[c] = loc[3+strlen("expiryDate")+c];
  9659. c++;
  9660. }
  9661. sstr[c] = '\0';
  9662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9663. }
  9664. //***********************parentIdTag************************/
  9665. loc = strstr(payload, "parentIdTag");
  9666. if(loc != NULL)
  9667. {
  9668. memset(sstr ,0, sizeof(sstr) );
  9669. c = 0;
  9670. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9671. {
  9672. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9673. c++;
  9674. }
  9675. sstr[c] = '\0';
  9676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9677. }
  9678. //***********************status************************/
  9679. loc = strstr(payload, "status");
  9680. memset(sstr ,0, sizeof(sstr) );
  9681. c = 0;
  9682. while (loc[3+strlen("status")+c] != '\"')
  9683. {
  9684. sstr[c] = loc[3+strlen("status")+c];
  9685. c++;
  9686. }
  9687. sstr[c] = '\0';
  9688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9689. }
  9690. #ifdef SystemLogMessage
  9691. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9692. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9693. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9694. #endif
  9695. }
  9696. //==========================================
  9697. // Handle Error routine
  9698. //==========================================
  9699. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9700. {
  9701. mtrace();
  9702. #ifdef SystemLogMessage
  9703. DEBUG_INFO("errorCode: %s\n", errorCode);
  9704. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9705. DEBUG_INFO("errorDetails: %s\n", payload);
  9706. #endif
  9707. }
  9708. //===============================================
  9709. // Common routine
  9710. //===============================================
  9711. int initialConfigurationTable(void)
  9712. {
  9713. //clock_t start_t, end_t, total_t;
  9714. FILE *fp;
  9715. FILE *outfile;
  9716. char str[200]={0};
  9717. char sstr[100]={0};
  9718. int c = 0;
  9719. char *loc;
  9720. printf("initialConfigurationTable \n");
  9721. //start_t = clock();
  9722. //printf("Starting of the program, start_t = %ld\n", start_t);
  9723. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9724. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9725. {
  9726. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9727. if(outfile == NULL) {
  9728. DEBUG_INFO("Error opening file");
  9729. return FALSE;
  9730. }
  9731. /*Core Profile*/
  9732. //AllowOfflineTxForUnknownId
  9733. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 0;
  9734. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", "FALSE");
  9738. //AuthorizationCacheEnabled
  9739. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9743. //AuthorizeRemoteTxRequests
  9744. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9748. //BlinkRepeat
  9749. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9753. //ClockAlignedDataInterval
  9754. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9758. //ConnectionTimeOut
  9759. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9763. //GetConfigurationMaxKeys
  9764. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9768. // HeartbeatInterval
  9769. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9773. // LightIntensity
  9774. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9778. // LocalAuthorizeOffline
  9779. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9783. // LocalPreAuthorize
  9784. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9788. // MaxEnergyOnInvalidId
  9789. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9792. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9794. // MeterValuesAlignedData
  9795. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9799. // MeterValuesAlignedDataMaxLength
  9800. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9804. // MeterValuesSampledData
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9809. // MeterValuesSampledDataMaxLength
  9810. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9814. // MeterValueSampleInterval
  9815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9819. // MinimumStatusDuration
  9820. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9823. server_cycle_Status = 120; //StatusNotification cycle
  9824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9825. // NumberOfConnectors
  9826. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9829. {
  9830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9831. }
  9832. else
  9833. {
  9834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9835. }
  9836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9837. // ResetRetries
  9838. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9842. // ConnectorPhaseRotation
  9843. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9847. // ConnectorPhaseRotationMaxLength
  9848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9852. // StopTransactionOnEVSideDisconnect
  9853. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9857. // StopTransactionOnInvalidId
  9858. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9862. // StopTxnAlignedData
  9863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9867. // StopTxnAlignedDataMaxLength
  9868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9872. // StopTxnSampledData
  9873. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9877. // StopTxnSampledDataMaxLength
  9878. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9881. {
  9882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9883. }
  9884. else
  9885. {
  9886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9887. }
  9888. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9890. // SupportedFeatureProfiles
  9891. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9895. // SupportedFeatureProfilesMaxLength
  9896. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9900. // TransactionMessageAttempts
  9901. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9904. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9906. // TransactionMessageRetryInterval
  9907. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9910. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9912. // UnlockConnectorOnEVSideDisconnect
  9913. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9917. // WebSocketPingInterval
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9922. //* Local Auth List Management Profile*/
  9923. #if 0
  9924. //For OCTT Test Case
  9925. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9928. #endif
  9929. #if 1
  9930. //LocalAuthListEnabled
  9931. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9935. #endif
  9936. //LocalAuthListMaxLength
  9937. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9941. //SendLocalListMaxLength
  9942. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9946. //ReserveConnectorZeroSupported
  9947. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9951. //* Smart Charging Profile */
  9952. //ChargeProfileMaxStackLevel
  9953. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9957. // ChargingScheduleAllowedChargingRateUnit
  9958. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9962. // ChargingScheduleMaxPeriods
  9963. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9967. // ConnectorSwitch3to1PhaseSupported
  9968. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9972. // MaxChargingProfilesInstalled
  9973. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9977. fclose(outfile);
  9978. }
  9979. else
  9980. {
  9981. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9982. char keystr[60]={0};
  9983. char readonlystr[10]={0};
  9984. char valuestr[100]={0};
  9985. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9986. if(fp == NULL) {
  9987. DEBUG_INFO("Error opening file");
  9988. return FALSE;
  9989. }
  9990. while( fgets (str, sizeof(str), fp)!=NULL )
  9991. {
  9992. //DEBUG_INFO("Get Configuration \n");
  9993. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9994. //*************************key*********************************/
  9995. loc = strstr(str, "key");
  9996. c = 0;
  9997. memset(sstr ,0, sizeof(sstr) );
  9998. while (loc[strlen("key")+3+c] != '\"')
  9999. {
  10000. sstr[c] = loc[strlen("key")+3+c];
  10001. c++;
  10002. }
  10003. sstr[c] = '\0';
  10004. strcpy(keystr,sstr);
  10005. //*************************readonly*********************************/
  10006. loc = strstr(str, "readonly");
  10007. c = 0;
  10008. memset(sstr ,0, sizeof(sstr) );
  10009. while (loc[strlen("readonly")+2+c] != ',')
  10010. {
  10011. sstr[c] = loc[strlen("readonly")+2+c];
  10012. c++;
  10013. }
  10014. sstr[c] = '\0';
  10015. strcpy(readonlystr,sstr);
  10016. //*************************value*********************************/
  10017. loc = strstr(str, "value");
  10018. c = 0;
  10019. memset(sstr ,0, sizeof(sstr) );
  10020. while (loc[strlen("value")+3+c] != '\"')
  10021. {
  10022. sstr[c] = loc[strlen("value")+3+c];
  10023. c++;
  10024. }
  10025. sstr[c] = '\0';
  10026. strcpy(valuestr,sstr);
  10027. // DEBUG_INFO("keystr=%s\n",keystr);
  10028. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10029. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10030. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10031. {
  10032. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10033. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10035. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10036. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10037. }
  10038. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10039. {
  10040. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10041. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10043. }
  10044. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10045. {
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10048. }
  10049. if(strcmp(keystr, "BlinkRepeat") == 0)
  10050. {
  10051. //Charger.BlinkRepeat = Integer.parseInt(value);
  10052. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10054. }
  10055. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10056. {
  10057. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10059. }
  10060. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10061. {
  10062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10064. }
  10065. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10066. {
  10067. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10069. }
  10070. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10071. {
  10072. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10074. HeartBeatWaitTime = atoi(valuestr);
  10075. }
  10076. if(strcmp(keystr, "LightIntensity") == 0)
  10077. {
  10078. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10080. }
  10081. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10082. {
  10083. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10085. }
  10086. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10087. {
  10088. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10090. }
  10091. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10092. {
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10095. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10096. }
  10097. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10098. {
  10099. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10101. }
  10102. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10103. {
  10104. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10106. }
  10107. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10108. {
  10109. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10111. }
  10112. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10113. {
  10114. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10116. }
  10117. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10118. {
  10119. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10121. }
  10122. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10123. {
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10126. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10127. }
  10128. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10129. {
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10132. }
  10133. if(strcmp(keystr, "ResetRetries") == 0)
  10134. {
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10137. }
  10138. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10139. {
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10142. }
  10143. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10144. {
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10147. }
  10148. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10149. {
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10152. }
  10153. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10154. {
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10157. }
  10158. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10159. {
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10162. }
  10163. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10164. {
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10167. }
  10168. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10169. {
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10172. }
  10173. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10174. {
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10177. }
  10178. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10179. {
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10182. }
  10183. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10184. {
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10187. }
  10188. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10189. {
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10192. TransactionMessageAttemptsValue = atoi(valuestr);
  10193. }
  10194. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10195. {
  10196. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10198. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10199. }
  10200. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10201. {
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10204. }
  10205. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10206. {
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10209. }
  10210. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10211. {
  10212. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10214. }
  10215. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10216. {
  10217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10219. }
  10220. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10221. {
  10222. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10224. }
  10225. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10226. {
  10227. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10229. }
  10230. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10231. {
  10232. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10234. }
  10235. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10236. {
  10237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10239. }
  10240. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10241. {
  10242. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10244. }
  10245. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10246. {
  10247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10249. }
  10250. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10251. {
  10252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10254. }
  10255. }
  10256. fclose(fp);
  10257. }
  10258. //end_t = clock();
  10259. //printf("End of the big loop, end_t = %ld\n", end_t);
  10260. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10261. //printf("Total time taken by CPU: %f\n", total_t );
  10262. return 0;
  10263. }
  10264. void StoreConfigurationTable(void)
  10265. {
  10266. FILE *outfile;
  10267. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10268. if(outfile == NULL)
  10269. {
  10270. DEBUG_INFO("Error opening file");
  10271. return ;
  10272. }
  10273. /*Core Profile*/
  10274. //AllowOfflineTxForUnknownId
  10275. /*
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10277. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10280. */
  10281. //DEBUG_INFO("data=%s\n",data);
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10283. //AuthorizationCacheEnabled
  10284. /*
  10285. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10288. */
  10289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10290. //AuthorizeRemoteTxRequests
  10291. /*
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10295. */
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10297. //BlinkRepeat
  10298. /*
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10302. */
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10304. //ClockAlignedDataInterval
  10305. /*
  10306. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10309. */
  10310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10311. //ConnectionTimeOut
  10312. /*
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10316. */
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10318. //GetConfigurationMaxKeys
  10319. /*
  10320. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10323. */
  10324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10325. // HeartbeatInterval
  10326. /*
  10327. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10330. */
  10331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10332. // LightIntensity
  10333. /*
  10334. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10337. */
  10338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10339. // LocalAuthorizeOffline
  10340. /*
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10344. */
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10346. // LocalPreAuthorize
  10347. /*
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10351. */
  10352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10353. // MaxEnergyOnInvalidId
  10354. /*
  10355. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10358. */
  10359. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10361. // MeterValuesAlignedData
  10362. /*
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10366. */
  10367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10368. // MeterValuesAlignedDataMaxLength
  10369. /*
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10373. */
  10374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10375. // MeterValuesSampledData
  10376. /*
  10377. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10380. */
  10381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10382. // MeterValuesSampledDataMaxLength
  10383. /*
  10384. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10387. */
  10388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10389. // MeterValueSampleInterval
  10390. /*
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10394. */
  10395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10396. // MinimumStatusDuration
  10397. /*
  10398. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10401. */
  10402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10403. // NumberOfConnectors
  10404. /*
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10408. {
  10409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10410. }
  10411. else
  10412. {
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10414. }
  10415. */
  10416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10417. // ResetRetries
  10418. /*
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10422. */
  10423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10424. // ConnectorPhaseRotation
  10425. /*
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10429. */
  10430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10431. // ConnectorPhaseRotationMaxLength
  10432. /*
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10436. */
  10437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10438. // StopTransactionOnEVSideDisconnect
  10439. /*
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10443. */
  10444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10445. // StopTransactionOnInvalidId
  10446. /*
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10450. */
  10451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10452. // StopTxnAlignedData
  10453. /*
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10457. */
  10458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10459. // StopTxnAlignedDataMaxLength
  10460. /*
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10464. */
  10465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10466. // StopTxnSampledData
  10467. /*
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10471. */
  10472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10473. // StopTxnSampledDataMaxLength
  10474. /*
  10475. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10478. */
  10479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10480. // SupportedFeatureProfiles
  10481. /*
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10485. */
  10486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10487. // SupportedFeatureProfilesMaxLength
  10488. /*
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10492. */
  10493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10494. // TransactionMessageAttempts
  10495. /*
  10496. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10499. */
  10500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10501. // TransactionMessageRetryInterval
  10502. /*
  10503. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10506. */
  10507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10508. // UnlockConnectorOnEVSideDisconnect
  10509. /*
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10513. */
  10514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10515. // WebSocketPingInterval
  10516. /*
  10517. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10520. */
  10521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10522. //* Local Auth List Management Profile*/
  10523. //LocalAuthListEnabled
  10524. /*
  10525. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10528. */
  10529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10530. //LocalAuthListMaxLength
  10531. /*
  10532. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10535. */
  10536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10537. //SendLocalListMaxLength
  10538. /*
  10539. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10542. */
  10543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10544. //ReserveConnectorZeroSupported
  10545. /*
  10546. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10549. */
  10550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10551. //* Smart Charging Profile */
  10552. //ChargeProfileMaxStackLevel
  10553. /*
  10554. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10557. */
  10558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10559. // ChargingScheduleAllowedChargingRateUnit
  10560. /*
  10561. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10564. */
  10565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10566. // ChargingScheduleMaxPeriods
  10567. /*
  10568. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10571. */
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10573. // ConnectorSwitch3to1PhaseSupported
  10574. /*
  10575. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10578. */
  10579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10580. // MaxChargingProfilesInstalled
  10581. /*
  10582. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10585. */
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10587. fclose(outfile);
  10588. }
  10589. void getKeyValue(char *keyReq)
  10590. {
  10591. int isEmpty = FALSE;
  10592. int isKnowKey = FALSE;
  10593. //int unKnowIndex = 0;
  10594. DEBUG_INFO("getKeyValue \n");
  10595. DEBUG_INFO("keyReq=%s \n",keyReq);
  10596. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10597. isEmpty = TRUE;
  10598. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10605. }
  10606. else
  10607. {
  10608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10609. }
  10610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10611. isKnowKey = TRUE;
  10612. }
  10613. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10614. {
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10618. {
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10620. }
  10621. else
  10622. {
  10623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10624. }
  10625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10626. isKnowKey = TRUE;
  10627. }
  10628. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10635. }
  10636. else
  10637. {
  10638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10639. }
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10641. isKnowKey = TRUE;
  10642. }
  10643. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10650. }
  10651. else
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10654. }
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10656. isKnowKey = TRUE;
  10657. }
  10658. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10659. {
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10665. }
  10666. else
  10667. {
  10668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10669. }
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10671. isKnowKey = TRUE;
  10672. }
  10673. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10674. {
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10684. }
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10686. isKnowKey = TRUE;
  10687. }
  10688. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10689. {
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10695. }
  10696. else
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10699. }
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10701. isKnowKey = TRUE;
  10702. }
  10703. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10704. {
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10710. }
  10711. else
  10712. {
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10714. }
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10716. isKnowKey = TRUE;
  10717. }
  10718. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10725. }
  10726. else
  10727. {
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10729. }
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10731. isKnowKey = TRUE;
  10732. }
  10733. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10734. {
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10740. }
  10741. else
  10742. {
  10743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10744. }
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10746. isKnowKey = TRUE;
  10747. }
  10748. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10755. }
  10756. else
  10757. {
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10759. }
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10761. isKnowKey = TRUE;
  10762. }
  10763. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10770. }
  10771. else
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10774. }
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10776. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10777. isKnowKey = TRUE;
  10778. }
  10779. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10780. {
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10784. {
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10786. }
  10787. else
  10788. {
  10789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10790. }
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10792. isKnowKey = TRUE;
  10793. }
  10794. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10795. {
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10799. {
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10801. }
  10802. else
  10803. {
  10804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10805. }
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10807. isKnowKey = TRUE;
  10808. }
  10809. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10810. {
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10814. {
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10816. }
  10817. else
  10818. {
  10819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10820. }
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10822. isKnowKey = TRUE;
  10823. }
  10824. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10825. {
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10829. {
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10831. }
  10832. else
  10833. {
  10834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10835. }
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10837. isKnowKey = TRUE;
  10838. }
  10839. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10840. {
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10844. {
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10846. }
  10847. else
  10848. {
  10849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10850. }
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10852. isKnowKey = TRUE;
  10853. }
  10854. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10855. {
  10856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10859. {
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10861. }
  10862. else
  10863. {
  10864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10865. }
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10867. isKnowKey = TRUE;
  10868. }
  10869. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10870. {
  10871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10874. {
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10876. }
  10877. else
  10878. {
  10879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10880. }
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10882. isKnowKey = TRUE;
  10883. }
  10884. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10885. {
  10886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10889. {
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10891. }
  10892. else
  10893. {
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10895. }
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10897. isKnowKey = TRUE;
  10898. }
  10899. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10900. {
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10904. {
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10906. }
  10907. else
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10910. }
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10912. isKnowKey = TRUE;
  10913. }
  10914. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10915. {
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10919. {
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10921. }
  10922. else
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10925. }
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10927. isKnowKey = TRUE;
  10928. }
  10929. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10930. {
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10936. }
  10937. else
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10940. }
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10942. isKnowKey = TRUE;
  10943. }
  10944. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10951. }
  10952. else
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10955. }
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10957. isKnowKey = TRUE;
  10958. }
  10959. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10966. }
  10967. else
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10970. }
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10972. isKnowKey = TRUE;
  10973. }
  10974. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10981. }
  10982. else
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10985. }
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10987. isKnowKey = TRUE;
  10988. }
  10989. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10996. }
  10997. else
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11000. }
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11002. isKnowKey = TRUE;
  11003. }
  11004. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11011. }
  11012. else
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11015. }
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11017. isKnowKey = TRUE;
  11018. }
  11019. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11026. }
  11027. else
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11030. }
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11032. isKnowKey = TRUE;
  11033. }
  11034. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11041. }
  11042. else
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11045. }
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11047. isKnowKey = TRUE;
  11048. }
  11049. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11056. }
  11057. else
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11060. }
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11062. isKnowKey = TRUE;
  11063. }
  11064. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11071. }
  11072. else
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11075. }
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11077. isKnowKey = TRUE;
  11078. }
  11079. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11086. }
  11087. else
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11090. }
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11092. isKnowKey = TRUE;
  11093. }
  11094. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11101. }
  11102. else
  11103. {
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11105. }
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11107. isKnowKey = TRUE;
  11108. }
  11109. #if 0
  11110. //For OCTT Test Case
  11111. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11115. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11118. }
  11119. else
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11122. }
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11124. isKnowKey = TRUE;
  11125. }
  11126. #endif
  11127. #if 1
  11128. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11132. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11135. }
  11136. else
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11139. }
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11141. isKnowKey = TRUE;
  11142. }
  11143. #endif
  11144. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11148. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11151. }
  11152. else
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11155. }
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11157. isKnowKey = TRUE;
  11158. }
  11159. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11163. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11166. }
  11167. else
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11170. }
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11172. isKnowKey = TRUE;
  11173. }
  11174. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11178. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11181. }
  11182. else
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11185. }
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11187. isKnowKey = TRUE;
  11188. }
  11189. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11193. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11196. }
  11197. else
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11200. }
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11202. isKnowKey = TRUE;
  11203. }
  11204. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11205. {
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11208. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11211. }
  11212. else
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11215. }
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11217. isKnowKey = TRUE;
  11218. }
  11219. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11223. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11224. {
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11226. }
  11227. else
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11230. }
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11232. isKnowKey = TRUE;
  11233. }
  11234. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11238. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11239. {
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11241. }
  11242. else
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11245. }
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11247. isKnowKey = TRUE;
  11248. }
  11249. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11253. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11254. {
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11256. }
  11257. else
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11260. }
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11262. isKnowKey = TRUE;
  11263. }
  11264. //=========================================================
  11265. if(!isEmpty && !isKnowKey)
  11266. {
  11267. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11268. strcpy(unknownkey[UnknownKeynum], keyReq);
  11269. UnknownKeynum = UnknownKeynum + 1;
  11270. }
  11271. }
  11272. void processUnkownKey(void)
  11273. {
  11274. DEBUG_INFO("processUnkownKey\n");
  11275. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11276. for(int index=0; index < UnknownKeynum; index++)
  11277. {
  11278. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11279. {
  11280. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11281. }
  11282. }
  11283. }
  11284. int setKeyValue(char *key, char *value)
  11285. {
  11286. int isSuccess = NotSupported;
  11287. int check_ascii=0;
  11288. char str[10]={0};
  11289. #ifdef Debug
  11290. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11291. #endif
  11292. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11293. {
  11294. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11296. {
  11297. strcpy(str, (const char*)value);
  11298. for(int i = 0; str[i]; i++){
  11299. str[i] = tolower(str[i]);
  11300. }
  11301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11302. isSuccess = ConfigurationStatus_Accepted;
  11303. }
  11304. else
  11305. {
  11306. isSuccess = ConfigurationStatus_Rejected;
  11307. }
  11308. }
  11309. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11310. {
  11311. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11313. {
  11314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11315. isSuccess = ConfigurationStatus_Accepted;
  11316. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11317. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11318. }
  11319. else
  11320. {
  11321. isSuccess = ConfigurationStatus_Rejected;
  11322. }
  11323. }
  11324. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11325. {
  11326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11327. {
  11328. strcpy(str, (const char*)value);
  11329. for(int i = 0; str[i]; i++)
  11330. {
  11331. str[i] = tolower(str[i]);
  11332. }
  11333. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11335. isSuccess = ConfigurationStatus_Accepted;
  11336. }
  11337. else
  11338. {
  11339. isSuccess = ConfigurationStatus_Rejected;
  11340. }
  11341. }
  11342. if(strcmp(key, "BlinkRepeat") == 0)
  11343. {
  11344. //Charger.BlinkRepeat = Integer.parseInt(value);
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11346. {
  11347. check_ascii = value[0];
  11348. if( (check_ascii < 48) || (check_ascii > 57) )
  11349. {
  11350. isSuccess = ConfigurationStatus_Rejected;
  11351. }
  11352. else
  11353. {
  11354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11355. isSuccess = ConfigurationStatus_Accepted;
  11356. }
  11357. }
  11358. else
  11359. {
  11360. isSuccess = ConfigurationStatus_Rejected;
  11361. }
  11362. }
  11363. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11364. {
  11365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11366. {
  11367. check_ascii = value[0];
  11368. if( (check_ascii < 48) || (check_ascii > 57) )
  11369. {
  11370. isSuccess = ConfigurationStatus_Rejected;
  11371. }
  11372. else
  11373. {
  11374. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11376. isSuccess = ConfigurationStatus_Accepted;
  11377. }
  11378. }
  11379. else
  11380. {
  11381. isSuccess = ConfigurationStatus_Rejected;
  11382. }
  11383. }
  11384. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11385. {
  11386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11387. {
  11388. check_ascii = value[0];
  11389. if( (check_ascii < 48) || (check_ascii > 57) )
  11390. {
  11391. isSuccess = ConfigurationStatus_Rejected;
  11392. }
  11393. else
  11394. {
  11395. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11397. isSuccess = ConfigurationStatus_Accepted;
  11398. }
  11399. }
  11400. else
  11401. {
  11402. isSuccess = ConfigurationStatus_Rejected;
  11403. }
  11404. }
  11405. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11406. {
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11408. {
  11409. check_ascii = value[0];
  11410. if( (check_ascii < 48) || (check_ascii > 57) )
  11411. {
  11412. isSuccess = ConfigurationStatus_Rejected;
  11413. }
  11414. else
  11415. {
  11416. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11418. isSuccess = ConfigurationStatus_Accepted;
  11419. }
  11420. }
  11421. else
  11422. {
  11423. isSuccess = ConfigurationStatus_Rejected;
  11424. }
  11425. }
  11426. if(strcmp(key, "HeartbeatInterval") == 0)
  11427. {
  11428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11429. {
  11430. check_ascii = value[0];
  11431. if( (check_ascii < 48) || (check_ascii > 57) )
  11432. {
  11433. isSuccess = ConfigurationStatus_Rejected;
  11434. }
  11435. else
  11436. {
  11437. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11439. HeartBeatWaitTime = atoi(value);
  11440. isSuccess = ConfigurationStatus_Accepted;
  11441. }
  11442. }
  11443. else
  11444. {
  11445. isSuccess = ConfigurationStatus_Rejected;
  11446. }
  11447. }
  11448. if(strcmp(key, "LightIntensity") == 0)
  11449. {
  11450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11451. {
  11452. check_ascii = value[0];
  11453. if( (check_ascii < 48) || (check_ascii > 57) )
  11454. {
  11455. isSuccess = ConfigurationStatus_Rejected;
  11456. }
  11457. else
  11458. {
  11459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11460. isSuccess = ConfigurationStatus_Accepted;
  11461. }
  11462. }
  11463. else
  11464. {
  11465. isSuccess = ConfigurationStatus_Rejected;
  11466. }
  11467. }
  11468. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11469. {
  11470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11471. {
  11472. strcpy(str, (const char*)value);
  11473. for(int i = 0; str[i]; i++)
  11474. {
  11475. str[i] = tolower(str[i]);
  11476. }
  11477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11478. isSuccess = ConfigurationStatus_Accepted;
  11479. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11480. }
  11481. else
  11482. {
  11483. isSuccess = ConfigurationStatus_Rejected;
  11484. }
  11485. }
  11486. if(strcmp(key, "LocalPreAuthorize") == 0)
  11487. {
  11488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11489. {
  11490. strcpy(str, (const char*)value);
  11491. for(int i = 0; str[i]; i++)
  11492. {
  11493. str[i] = tolower(str[i]);
  11494. }
  11495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11496. isSuccess = ConfigurationStatus_Accepted;
  11497. }
  11498. else
  11499. {
  11500. isSuccess = ConfigurationStatus_Rejected;
  11501. }
  11502. }
  11503. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11504. {
  11505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11506. {
  11507. check_ascii = value[0];
  11508. if( (check_ascii < 48) || (check_ascii > 57) )
  11509. {
  11510. isSuccess = ConfigurationStatus_Rejected;
  11511. }
  11512. else
  11513. {
  11514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11515. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11516. isSuccess = ConfigurationStatus_Accepted;
  11517. }
  11518. }
  11519. else
  11520. {
  11521. isSuccess = ConfigurationStatus_Rejected;
  11522. }
  11523. }
  11524. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11525. {
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11527. {
  11528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11529. isSuccess = ConfigurationStatus_Accepted;
  11530. }
  11531. else
  11532. {
  11533. isSuccess = ConfigurationStatus_Rejected;
  11534. }
  11535. }
  11536. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11537. {
  11538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11539. {
  11540. check_ascii = value[0];
  11541. if( (check_ascii < 48) || (check_ascii > 57) )
  11542. {
  11543. isSuccess = ConfigurationStatus_Rejected;
  11544. }
  11545. else
  11546. {
  11547. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11549. isSuccess = ConfigurationStatus_Accepted;
  11550. }
  11551. }
  11552. else
  11553. {
  11554. isSuccess = ConfigurationStatus_Rejected;
  11555. }
  11556. }
  11557. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11558. {
  11559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11560. {
  11561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11562. isSuccess = ConfigurationStatus_Accepted;
  11563. }
  11564. else
  11565. {
  11566. isSuccess = ConfigurationStatus_Rejected;
  11567. }
  11568. }
  11569. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11570. {
  11571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11572. {
  11573. check_ascii = value[0];
  11574. if( (check_ascii < 48) || (check_ascii > 57) )
  11575. {
  11576. isSuccess = ConfigurationStatus_Rejected;
  11577. }
  11578. else
  11579. {
  11580. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11582. isSuccess = ConfigurationStatus_Accepted;
  11583. }
  11584. }
  11585. else
  11586. {
  11587. isSuccess = ConfigurationStatus_Rejected;
  11588. }
  11589. }
  11590. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11591. {
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11593. {
  11594. check_ascii = value[0];
  11595. if( (check_ascii < 48) || (check_ascii > 57) )
  11596. {
  11597. isSuccess = ConfigurationStatus_Rejected;
  11598. }
  11599. else
  11600. {
  11601. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11603. isSuccess = ConfigurationStatus_Accepted;
  11604. }
  11605. }
  11606. else
  11607. {
  11608. isSuccess = ConfigurationStatus_Rejected;
  11609. }
  11610. }
  11611. if(strcmp(key, "MinimumStatusDuration") == 0)
  11612. {
  11613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11614. {
  11615. check_ascii = value[0];
  11616. if( (check_ascii < 48) || (check_ascii > 57) )
  11617. {
  11618. isSuccess = ConfigurationStatus_Rejected;
  11619. }
  11620. else
  11621. {
  11622. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11624. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11625. isSuccess = ConfigurationStatus_Accepted;
  11626. }
  11627. }
  11628. else
  11629. {
  11630. isSuccess = ConfigurationStatus_Rejected;
  11631. }
  11632. }
  11633. if(strcmp(key, "NumberOfConnectors") == 0)
  11634. {
  11635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11636. {
  11637. check_ascii = value[0];
  11638. if( (check_ascii < 48) || (check_ascii > 57) )
  11639. {
  11640. isSuccess = ConfigurationStatus_Rejected;
  11641. }
  11642. else
  11643. {
  11644. //Charger.ResetRetries = Integer.parseInt(value);
  11645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11646. isSuccess = ConfigurationStatus_Accepted;
  11647. }
  11648. }
  11649. else
  11650. {
  11651. isSuccess = ConfigurationStatus_Rejected;
  11652. }
  11653. }
  11654. if(strcmp(key, "ResetRetries") == 0)
  11655. {
  11656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11657. {
  11658. check_ascii = value[0];
  11659. if( (check_ascii < 48) || (check_ascii > 57) )
  11660. {
  11661. isSuccess = ConfigurationStatus_Rejected;
  11662. }
  11663. else
  11664. {
  11665. //Charger.ResetRetries = Integer.parseInt(value);
  11666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11667. isSuccess = ConfigurationStatus_Accepted;
  11668. }
  11669. }
  11670. else
  11671. {
  11672. isSuccess = ConfigurationStatus_Rejected;
  11673. }
  11674. }
  11675. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11676. {
  11677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11678. {
  11679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11680. isSuccess = ConfigurationStatus_Accepted;
  11681. }
  11682. else
  11683. {
  11684. isSuccess = ConfigurationStatus_Rejected;
  11685. }
  11686. }
  11687. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11688. {
  11689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11690. {
  11691. check_ascii = value[0];
  11692. if( (check_ascii < 48) || (check_ascii > 57) )
  11693. {
  11694. isSuccess = ConfigurationStatus_Rejected;
  11695. }
  11696. else
  11697. {
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11699. isSuccess = ConfigurationStatus_Accepted;
  11700. }
  11701. }
  11702. else
  11703. {
  11704. isSuccess = ConfigurationStatus_Rejected;
  11705. }
  11706. }
  11707. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11708. {
  11709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11710. {
  11711. strcpy(str, (const char*)value);
  11712. for(int i = 0; str[i]; i++)
  11713. {
  11714. str[i] = tolower(str[i]);
  11715. }
  11716. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11718. isSuccess = ConfigurationStatus_Accepted;
  11719. }
  11720. else
  11721. {
  11722. isSuccess = ConfigurationStatus_Rejected;
  11723. }
  11724. }
  11725. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11726. {
  11727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11728. {
  11729. strcpy(str, (const char*)value);
  11730. for(int i = 0; str[i]; i++)
  11731. {
  11732. str[i] = tolower(str[i]);
  11733. }
  11734. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11736. isSuccess = ConfigurationStatus_Accepted;
  11737. }
  11738. else
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. }
  11743. if(strcmp(key, "StopTxnAlignedData") == 0)
  11744. {
  11745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11746. {
  11747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11748. isSuccess = ConfigurationStatus_Accepted;
  11749. }
  11750. else
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. }
  11755. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11756. {
  11757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11758. {
  11759. check_ascii = value[0];
  11760. if( (check_ascii < 48) || (check_ascii > 57) )
  11761. {
  11762. isSuccess = ConfigurationStatus_Rejected;
  11763. }
  11764. else
  11765. {
  11766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11767. isSuccess = ConfigurationStatus_Accepted;
  11768. }
  11769. }
  11770. else
  11771. {
  11772. isSuccess = ConfigurationStatus_Rejected;
  11773. }
  11774. }
  11775. if(strcmp(key, "StopTxnSampledData") == 0)
  11776. {
  11777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11778. {
  11779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11780. isSuccess = ConfigurationStatus_Accepted;
  11781. }
  11782. else
  11783. {
  11784. isSuccess = ConfigurationStatus_Rejected;
  11785. }
  11786. }
  11787. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11788. {
  11789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11790. {
  11791. check_ascii = value[0];
  11792. if( (check_ascii < 48) || (check_ascii > 57) )
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. else
  11797. {
  11798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11799. isSuccess = ConfigurationStatus_Accepted;
  11800. }
  11801. }
  11802. else
  11803. {
  11804. isSuccess = ConfigurationStatus_Rejected;
  11805. }
  11806. }
  11807. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11808. {
  11809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11810. {
  11811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11812. isSuccess = ConfigurationStatus_Accepted;
  11813. }
  11814. else
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. }
  11819. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11820. {
  11821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11822. {
  11823. check_ascii = value[0];
  11824. if( (check_ascii < 48) || (check_ascii > 57) )
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. else
  11829. {
  11830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11831. isSuccess = ConfigurationStatus_Accepted;
  11832. }
  11833. }
  11834. else
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. }
  11839. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11840. {
  11841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11842. {
  11843. check_ascii = value[0];
  11844. if( (check_ascii < 48) || (check_ascii > 57) )
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. else
  11849. {
  11850. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11852. TransactionMessageAttemptsValue = atoi(value);
  11853. isSuccess = ConfigurationStatus_Accepted;
  11854. }
  11855. }
  11856. else
  11857. {
  11858. isSuccess = ConfigurationStatus_Rejected;
  11859. }
  11860. }
  11861. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11862. {
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11864. {
  11865. check_ascii = value[0];
  11866. if( (check_ascii < 48) || (check_ascii > 57) )
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. else
  11871. {
  11872. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11874. TransactionMessageRetryIntervalValue = atoi(value);
  11875. isSuccess = ConfigurationStatus_Accepted;
  11876. }
  11877. }
  11878. else
  11879. {
  11880. isSuccess = ConfigurationStatus_Rejected;
  11881. }
  11882. }
  11883. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11884. {
  11885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11886. {
  11887. strcpy(str, (const char*)value);
  11888. for(int i = 0; str[i]; i++)
  11889. {
  11890. str[i] = tolower(str[i]);
  11891. }
  11892. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. else
  11897. {
  11898. isSuccess = ConfigurationStatus_Rejected;
  11899. }
  11900. }
  11901. if(strcmp(key, "WebSocketPingInterval") == 0)
  11902. {
  11903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11904. {
  11905. check_ascii = value[0];
  11906. if( (check_ascii < 48) || (check_ascii > 57) )
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. else
  11911. {
  11912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11913. isSuccess = ConfigurationStatus_Accepted;
  11914. }
  11915. }
  11916. else
  11917. {
  11918. isSuccess = ConfigurationStatus_Rejected;
  11919. }
  11920. }
  11921. #if 0
  11922. //For OCPP Test Case
  11923. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11924. {
  11925. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11926. {
  11927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11928. isSuccess = ConfigurationStatus_Accepted;
  11929. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11930. }
  11931. else
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. }
  11936. #endif
  11937. #if 1
  11938. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11939. {
  11940. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11941. {
  11942. strcpy(str, (const char*)value);
  11943. for(int i = 0; str[i]; i++)
  11944. {
  11945. str[i] = tolower(str[i]);
  11946. }
  11947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11948. isSuccess = ConfigurationStatus_Accepted;
  11949. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11950. }
  11951. else
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. }
  11956. #endif
  11957. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11958. {
  11959. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11960. {
  11961. check_ascii = value[0];
  11962. if( (check_ascii < 48) || (check_ascii > 57) )
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. else
  11967. {
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11969. isSuccess = ConfigurationStatus_Accepted;
  11970. }
  11971. }
  11972. else
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. }
  11977. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11978. {
  11979. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11980. {
  11981. check_ascii = value[0];
  11982. if( (check_ascii < 48) || (check_ascii > 57) )
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. else
  11987. {
  11988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11989. isSuccess = ConfigurationStatus_Accepted;
  11990. }
  11991. }
  11992. else
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. }
  11997. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11998. {
  11999. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12000. {
  12001. strcpy(str, (const char*)value);
  12002. for(int i = 0; str[i]; i++)
  12003. {
  12004. str[i] = tolower(str[i]);
  12005. }
  12006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12007. isSuccess = ConfigurationStatus_Accepted;
  12008. }
  12009. else
  12010. {
  12011. isSuccess = ConfigurationStatus_Rejected;
  12012. }
  12013. }
  12014. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12015. {
  12016. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12017. {
  12018. check_ascii = value[0];
  12019. if( (check_ascii < 48) || (check_ascii > 57) )
  12020. {
  12021. isSuccess = ConfigurationStatus_Rejected;
  12022. }
  12023. else
  12024. {
  12025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12026. isSuccess = ConfigurationStatus_Accepted;
  12027. }
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. }
  12046. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12047. {
  12048. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12049. {
  12050. check_ascii = value[0];
  12051. if( (check_ascii < 48) || (check_ascii > 57) )
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. else
  12056. {
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12058. isSuccess = ConfigurationStatus_Accepted;
  12059. }
  12060. }
  12061. else
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. }
  12066. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12067. {
  12068. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12069. {
  12070. strcpy(str, (const char*)value);
  12071. for(int i = 0; str[i]; i++)
  12072. {
  12073. str[i] = tolower(str[i]);
  12074. }
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12076. isSuccess = ConfigurationStatus_Accepted;
  12077. }
  12078. else
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. }
  12083. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12084. {
  12085. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12086. {
  12087. check_ascii = value[0];
  12088. if( (check_ascii < 48) || (check_ascii > 57) )
  12089. {
  12090. isSuccess = ConfigurationStatus_Rejected;
  12091. }
  12092. else
  12093. {
  12094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. }
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. return isSuccess;
  12104. }
  12105. int updateSetting(char *key, char *value)
  12106. {
  12107. mtrace();
  12108. int isSuccess = FALSE;
  12109. char string[1000]={0}, buffer[1000]={0};
  12110. char strtemp[50]={0};
  12111. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12112. int pos, c = 0;
  12113. char *loc;
  12114. int pos1=0;
  12115. FILE *f = fopen("/var/www/settings1", "r");
  12116. if(f == NULL)
  12117. {
  12118. #ifdef Debug
  12119. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12120. #endif
  12121. return isSuccess;
  12122. }
  12123. fseek(f, 0, SEEK_END);
  12124. long fsize = ftell(f);
  12125. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12126. fread(string, 1, fsize, f);
  12127. fclose(f);
  12128. string[fsize] = 0;
  12129. loc = strstr(string, key);
  12130. if(loc != NULL)
  12131. {
  12132. DEBUG_INFO("key exist!\n");
  12133. pos = loc - string-1;
  12134. f = fopen("/var/www/settings1", "w");
  12135. strncpy(buffer, string, pos);
  12136. fprintf(f, "%s", buffer);
  12137. memset(sstr ,0, sizeof(sstr) );
  12138. c = 0;
  12139. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12140. {
  12141. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12142. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12143. c++;
  12144. }
  12145. sstr[c] = '\0';
  12146. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12147. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12148. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12149. memset(buffer ,0, sizeof(buffer) );
  12150. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12151. //printf("buffer=%s",buffer);
  12152. fprintf(f, "%s", buffer);
  12153. fclose(f);
  12154. }
  12155. else
  12156. {
  12157. printf("key not exist!\n");
  12158. f = fopen("/var/www/settings1", "w+");
  12159. fputs(string, f);
  12160. fseek(f, -1, SEEK_CUR);
  12161. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12162. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12163. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12164. fclose(f);
  12165. }
  12166. isSuccess = TRUE;
  12167. return isSuccess;
  12168. }
  12169. int TransactionMessageAttemptsGet(void)
  12170. {
  12171. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12172. }
  12173. int FirstHeartBeatResponse(void)
  12174. {
  12175. return FirstHeartBeat;
  12176. }
  12177. int TransactionMessageRetryIntervalGet(void)
  12178. {
  12179. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12180. }
  12181. #define SA struct sockaddr
  12182. #define MAXBUF 1024
  12183. //static int m_socket_data;
  12184. //static int sockfd;
  12185. int ReadHttpStatus(int sock){
  12186. //char c;
  12187. char buff[1024]="",*ptr=buff+1;
  12188. int bytes_received, status;
  12189. DEBUG_INFO("Begin Response ..\n");
  12190. while((bytes_received = recv(sock, ptr, 1, 0))){
  12191. if(bytes_received==-1){
  12192. perror("ReadHttpStatus");
  12193. exit(1);
  12194. }
  12195. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12196. ptr++;
  12197. }
  12198. *ptr=0;
  12199. ptr=buff+1;
  12200. sscanf(ptr,"%*s %d ", &status);
  12201. DEBUG_INFO("%s\n",ptr);
  12202. DEBUG_INFO("status=%d\n",status);
  12203. DEBUG_INFO("End Response ..\n");
  12204. return (bytes_received>0)?status:0;
  12205. }
  12206. //the only filed that it parsed is 'Content-Length'
  12207. int ParseHeader(int sock){
  12208. //char c;
  12209. char buff[1024]="",*ptr=buff+4;
  12210. int bytes_received;
  12211. DEBUG_INFO("Begin HEADER ..\n");
  12212. while((bytes_received = recv(sock, ptr, 1, 0))){
  12213. if(bytes_received==-1){
  12214. perror("Parse Header");
  12215. exit(1);
  12216. }
  12217. if(
  12218. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12219. (ptr[-1]=='\r') && (*ptr=='\n' )
  12220. ) break;
  12221. ptr++;
  12222. }
  12223. *ptr=0;
  12224. ptr=buff+4;
  12225. //printf("%s",ptr);
  12226. if(bytes_received){
  12227. ptr=strstr(ptr,"Content-Length:");
  12228. if(ptr){
  12229. sscanf(ptr,"%*s %d",&bytes_received);
  12230. }else
  12231. bytes_received=-1; //unknown size
  12232. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12233. }
  12234. DEBUG_INFO("End HEADER ..\n");
  12235. return bytes_received ;
  12236. }
  12237. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12238. {
  12239. char rmFileCmd[100]={0};
  12240. char FilePath[100]={0};
  12241. char ftpbuf[200];
  12242. int systemresult;
  12243. //DEBUG_INFO("filename=%s\n",filename);
  12244. //DEBUG_INFO("url=%s\n",url);
  12245. sprintf(FilePath,"/mnt/%s",filename);
  12246. if((access(FilePath,F_OK))!=-1)
  12247. {
  12248. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12249. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12250. system(rmFileCmd);
  12251. }
  12252. memset(ftpbuf, 0, sizeof(ftpbuf));
  12253. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12254. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12255. systemresult = system(ftpbuf);
  12256. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12257. if(systemresult != 0)
  12258. {
  12259. DEBUG_INFO("http DownLoad error!\n");
  12260. return FALSE;
  12261. }
  12262. return TRUE;
  12263. }
  12264. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12265. {
  12266. char rmFileCmd[100]={0};
  12267. char FilePath[100]={0};
  12268. char ftpbuf[200];
  12269. int systemresult;
  12270. //char temp[100];
  12271. #if 0
  12272. struct hostent* server;
  12273. char *IPbuffer;
  12274. server = gethostbyname(location);
  12275. // To convert an Internet network
  12276. // address into ASCII string
  12277. IPbuffer = inet_ntoa(*((struct in_addr*)
  12278. server->h_addr_list[0]));
  12279. #endif
  12280. sprintf(FilePath,"/mnt/%s",filename);
  12281. if((access(FilePath,F_OK))!=-1)
  12282. {
  12283. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12284. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12285. system(rmFileCmd);
  12286. }
  12287. memset(ftpbuf, 0, sizeof(ftpbuf));
  12288. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12289. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12290. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12291. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12292. systemresult = system(ftpbuf);
  12293. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12294. if(systemresult != 0)
  12295. {
  12296. printf("wget error!\n");
  12297. return FALSE;
  12298. }
  12299. return TRUE;
  12300. }
  12301. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12302. {
  12303. char rmFileCmd[100]={0};
  12304. char FilePath[100]={0};
  12305. char ftpbuf[200];
  12306. char filenametemp[60]={0};
  12307. int systemresult;
  12308. //DEBUG_INFO("filename=%s\n",filename);
  12309. //DEBUG_INFO("url=%s\n",url);
  12310. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12311. if((access(FilePath,F_OK))!=-1)
  12312. {
  12313. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12314. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12315. system(rmFileCmd);
  12316. }
  12317. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12318. if(fp == NULL)
  12319. {
  12320. DEBUG_INFO("log is NULL\n");
  12321. return FALSE;
  12322. }
  12323. else
  12324. {
  12325. fprintf(fp, "%s\n", url);
  12326. sscanf(filename, "%*2[.]%s", filenametemp);
  12327. fprintf(fp, "%s\n", filenametemp);
  12328. fclose(fp);
  12329. }
  12330. memset(ftpbuf, 0, sizeof(ftpbuf));
  12331. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12332. systemresult = system(ftpbuf);
  12333. DEBUG_INFO("systemresult=%d\n",systemresult);
  12334. if(systemresult != 0)
  12335. {
  12336. DEBUG_INFO("http upload error!\n");
  12337. return FALSE;
  12338. }
  12339. return TRUE;
  12340. }
  12341. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12342. {
  12343. struct hostent* server;
  12344. char *IPbuffer;
  12345. char ftpbuf[200];
  12346. int systemresult;
  12347. // To retrieve host information
  12348. server = gethostbyname(location);
  12349. // To convert an Internet network
  12350. // address into ASCII string
  12351. IPbuffer = inet_ntoa(*((struct in_addr*)
  12352. server->h_addr_list[0]));
  12353. memset(ftpbuf, 0, sizeof(ftpbuf));
  12354. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12355. /* format : ftpput -u username -p passwd IP target source*/
  12356. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12357. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12358. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12359. systemresult = system(ftpbuf);
  12360. DEBUG_INFO("systemresult=%d\n",systemresult);
  12361. if(systemresult != 0)
  12362. {
  12363. DEBUG_INFO("ftpput error!\n");
  12364. return FALSE;
  12365. }
  12366. return TRUE;
  12367. }
  12368. int SettingChargingRecord(int target, int transactionId)
  12369. {
  12370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12371. {
  12372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12373. {
  12374. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12375. {
  12376. addBuff(target, transactionId, 0);
  12377. return TRUE;
  12378. }
  12379. }
  12380. for (int index = 0; index < CCS_QUANTITY; index++)
  12381. {
  12382. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12383. {
  12384. addBuff(target, transactionId, 0);
  12385. return TRUE;
  12386. }
  12387. }
  12388. for (int index = 0; index < GB_QUANTITY; index++)
  12389. {
  12390. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12391. {
  12392. addBuff(target, transactionId, 0);
  12393. return TRUE;
  12394. }
  12395. }
  12396. }
  12397. else
  12398. {
  12399. for (int index = 0; index < AC_QUANTITY; index++)
  12400. {
  12401. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12402. {
  12403. addBuff(target, transactionId, 0);
  12404. return TRUE;
  12405. }
  12406. }
  12407. }
  12408. return FALSE;
  12409. }
  12410. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12411. {
  12412. int isSuccess = FALSE;
  12413. //char *query = NULL;
  12414. sqlite3_stmt *stmt;
  12415. int rc; // return code
  12416. char str[20];
  12417. sprintf(str,"%d",user_id);
  12418. 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 */
  12419. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12420. rc = sqlite3_step(stmt); /* 3 */
  12421. if (rc != SQLITE_DONE) {
  12422. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12423. goto out;
  12424. }
  12425. sqlite3_finalize(stmt);
  12426. // free(query);
  12427. out:
  12428. //----------------------
  12429. // close SQLite database
  12430. //----------------------
  12431. sqlite3_close(db);
  12432. printf("database closed.\n");
  12433. return isSuccess;
  12434. }
  12435. /**
  12436. * Place the contents of the specified file into a memory buffer
  12437. *
  12438. * @param[in] filename The path and name of the file to read
  12439. * @param[out] filebuffer A pointer to the contents in memory
  12440. * @return status 0 success, 1 on failure
  12441. */
  12442. int get_file_contents(const char* filename, char** outbuffer) {
  12443. FILE* file = NULL;
  12444. long filesize;
  12445. const int blocksize = 1;
  12446. size_t readsize;
  12447. char* filebuffer;
  12448. // Open the file
  12449. file = fopen(filename, "r");
  12450. if (NULL == file)
  12451. {
  12452. printf("'%s' not opened\n", filename);
  12453. exit(EXIT_FAILURE);
  12454. }
  12455. // Determine the file size
  12456. fseek(file, 0, SEEK_END);
  12457. filesize = ftell(file);
  12458. rewind (file);
  12459. // Allocate memory for the file contents
  12460. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12461. *outbuffer = filebuffer;
  12462. if (filebuffer == NULL)
  12463. {
  12464. fputs ("malloc out-of-memory", stderr);
  12465. exit(EXIT_FAILURE);
  12466. }
  12467. // Read in the file
  12468. readsize = fread(filebuffer, blocksize, filesize, file);
  12469. if (readsize != filesize)
  12470. {
  12471. fputs ("didn't read file completely",stderr);
  12472. exit(EXIT_FAILURE);
  12473. }
  12474. // Clean exit
  12475. fclose(file);
  12476. return EXIT_SUCCESS;
  12477. }
  12478. static int selectSqlCount = 0;
  12479. static int callback(void *data, int argc, char **argv, char **azColName){
  12480. int i;
  12481. //printf("%s: ", (const char*)data);
  12482. selectSqlCount = argc;
  12483. for(i = 0; i<argc; i++){
  12484. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12485. }
  12486. //printf("\n");
  12487. return 0;
  12488. }
  12489. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12490. //int i;
  12491. //printf("%s:\n", (const char*)data);
  12492. localversion = argv[5] ? atoi(argv[5]) : 0;
  12493. //printf("localversion=%d\n", localversion);
  12494. return 0;
  12495. }
  12496. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12497. //int i;
  12498. //printf("%s:\n", (const char*)data);
  12499. //idTag
  12500. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12501. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12502. //parentIdTag
  12503. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12504. //expir_date
  12505. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12506. //status
  12507. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12508. //version
  12509. idTagQuery.listVersionInt = atoi(argv[5]);
  12510. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12511. return 0;
  12512. }
  12513. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12514. #if 0
  12515. int i;
  12516. //printf("%s:\n", (const char*)data);
  12517. for(i=0; i<argc; i++){
  12518. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12519. }
  12520. //printf("");
  12521. #endif
  12522. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12523. // printf("localversion=%d\n", localversion);
  12524. return 0;
  12525. }
  12526. /** sqlite3_exec的回调。
  12527. *
  12528. * 向控制台打印查询的结果。
  12529. *
  12530. * @param in data 传递给回调函数的数据。
  12531. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12532. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12533. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12534. * @return 状态码。
  12535. */
  12536. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12537. {
  12538. for (int i = 0; i < n_columns; i++)
  12539. {
  12540. DEBUG_INFO("%s/t", col_values[i]);
  12541. }
  12542. DEBUG_INFO("/n");
  12543. return 0;
  12544. }
  12545. void OCPP_getListVerion()
  12546. {
  12547. int rc = 0;
  12548. // const char* data = "Callback function called";
  12549. char sql[100];
  12550. char zErrMsg[100];
  12551. memset(sql, 0, 100);
  12552. memset(zErrMsg, 0, 100);
  12553. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12554. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12555. /* Execute SQL statement */
  12556. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12557. DEBUG_INFO("rc=%d\n",rc);
  12558. if( rc != SQLITE_OK ){
  12559. DEBUG_INFO("SQL error: %s", zErrMsg);
  12560. //sqlite3_free(zErrMsg);
  12561. }
  12562. }
  12563. void OCPP_getIdTag(char idTag[])
  12564. {
  12565. int rc = 0;
  12566. // const char* data = "Callback function called";
  12567. char sql[100];
  12568. char zErrMsg[100];
  12569. memset(sql, 0, 100);
  12570. memset(zErrMsg, 0, 100);
  12571. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12572. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12573. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12574. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12575. /* Execute SQL statement */
  12576. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12577. if( rc != SQLITE_OK ){
  12578. DEBUG_INFO("SQL error: %s", zErrMsg);
  12579. //sqlite3_free(zErrMsg);
  12580. }
  12581. //return ver;
  12582. }
  12583. void OCPP_get_TableAuthlocalAllData(void)
  12584. {
  12585. int rc = 0;
  12586. // const char* data = "Callback function called";
  12587. char sql[100];
  12588. char zErrMsg[100];
  12589. memset(sql, 0, 100);
  12590. memset(zErrMsg, 0, 100);
  12591. sprintf(sql,"select * from ocpp_auth_local ");
  12592. /* Execute SQL statement */
  12593. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12594. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12595. if( rc != SQLITE_OK ){
  12596. DEBUG_INFO("SQL error: %s", zErrMsg);
  12597. //sqlite3_free(zErrMsg);
  12598. }
  12599. //return ver;
  12600. }
  12601. int OCPP_cleanLocalList()
  12602. {
  12603. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12604. char *errMsg = 0;
  12605. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12606. if (SQLITE_OK != rc)
  12607. {
  12608. DEBUG_INFO("%s\n",errMsg);
  12609. return FALSE;
  12610. }
  12611. else
  12612. {
  12613. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12614. }
  12615. return TRUE;
  12616. }
  12617. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12618. {
  12619. int isSuccess = FALSE;
  12620. int ret = 0;
  12621. //const char* data = "Callback function called";
  12622. char sql[300];
  12623. char zErrMsg[200];
  12624. memset(sql, 0, 300);
  12625. memset(zErrMsg, 0, 200);
  12626. 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);
  12627. //* Execute SQL statement */
  12628. //zErrMsg = 0;
  12629. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12630. if( ret != SQLITE_OK ){
  12631. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12632. // free(zErrMsg);
  12633. // free(sql);
  12634. return isSuccess;
  12635. }
  12636. memset(sql, 0, 300);
  12637. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12638. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12639. if( ret != SQLITE_OK ){
  12640. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12641. // free(zErrMsg);
  12642. // free(sql);
  12643. return isSuccess;
  12644. }
  12645. // DEBUG_INFO("successfully Insert records created\n");
  12646. isSuccess = TRUE;
  12647. return isSuccess;
  12648. }
  12649. void OCPP_deleteIdTag(char idTag[])
  12650. {
  12651. //int ver = 0;
  12652. //int isSuccess = FALSE;
  12653. int rc = 0;
  12654. char sql[100];
  12655. char zErrMsg[100];
  12656. memset(sql, 0, 100);
  12657. memset(zErrMsg, 0, 100);
  12658. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12659. //* Execute SQL statement */
  12660. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12661. if( rc != SQLITE_OK ){
  12662. DEBUG_INFO("SQL error: %s", zErrMsg);
  12663. //sqlite3_free(zErrMsg);
  12664. }
  12665. }
  12666. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12667. {
  12668. int isSuccess = FALSE;
  12669. int ret = 0;
  12670. const char* data = "Callback function called";
  12671. char sql[200];
  12672. char zErrMsg[100];
  12673. memset(sql, 0, 200);
  12674. memset(zErrMsg, 0, 100);
  12675. //* selectFromTable */
  12676. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12677. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12678. //* Execute SQL statement */
  12679. selectSqlCount = 0;
  12680. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12681. if( ret != SQLITE_OK ){
  12682. printf("Error SQL: %s\n", zErrMsg);
  12683. }
  12684. printf("successfully select operation done\n");
  12685. memset(sql, 0, 200);
  12686. memset(zErrMsg, 0, 100);
  12687. if(selectSqlCount == 0)
  12688. {
  12689. //Insert
  12690. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12691. 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);
  12692. DEBUG_INFO("sql:%s\n", sql);
  12693. //* Execute SQL statement */
  12694. //zErrMsg = 0;
  12695. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12696. if( ret != SQLITE_OK ){
  12697. printf("SQL error: %s\n", zErrMsg);
  12698. return isSuccess;
  12699. }
  12700. DEBUG_INFO("successfully Insert records created\n");
  12701. isSuccess = TRUE;
  12702. }
  12703. else
  12704. {
  12705. //Update
  12706. //* Create merged SQL statement */
  12707. 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);
  12708. /* Execute SQL statement */
  12709. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12710. if( ret != SQLITE_OK ){
  12711. printf("SQL error: %s\n", zErrMsg);
  12712. //sqlite3_free(zErrMsg);
  12713. //sqlite3_free(sql);
  12714. return isSuccess;
  12715. }
  12716. DEBUG_INFO("Successfully operation done \n");
  12717. isSuccess = TRUE;
  12718. }
  12719. return isSuccess;
  12720. }
  12721. int GetOcppServerURL()
  12722. {
  12723. int result = FALSE;
  12724. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12725. memset(OcppHost, 0, sizeof(OcppHost));
  12726. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12727. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12728. {
  12729. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12730. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12731. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12732. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12733. result = TRUE;
  12734. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12735. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12736. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12737. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12738. goto End;
  12739. }
  12740. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12741. {
  12742. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12743. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12744. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12745. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12746. result = TRUE;
  12747. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12748. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12749. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12750. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12751. goto End;
  12752. }
  12753. else
  12754. {
  12755. strcpy(OcppHost,"");
  12756. }
  12757. End:
  12758. return result;
  12759. }
  12760. int GetOcppPath()
  12761. {
  12762. int result = FALSE;
  12763. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12764. {
  12765. if(OcppTempPath == NULL)
  12766. {
  12767. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12768. }
  12769. else
  12770. {
  12771. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12772. }
  12773. result = TRUE;
  12774. goto End;
  12775. }
  12776. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12777. {
  12778. if(OcppTempPath == NULL)
  12779. {
  12780. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12781. }
  12782. else
  12783. {
  12784. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12785. }
  12786. result = TRUE;
  12787. goto End;
  12788. }
  12789. else
  12790. {
  12791. strcpy(OcppPath,"");
  12792. }
  12793. End:
  12794. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12795. return result;
  12796. }
  12797. int GetOcppPort()
  12798. {
  12799. return OcppPort;
  12800. }
  12801. int GetOcppConnStatus(void)
  12802. {
  12803. return ShmOCPP16Data->OcppConnStatus;
  12804. }
  12805. void SetOcppConnStatus(uint8_t status)
  12806. {
  12807. ShmOCPP16Data->OcppConnStatus = status;
  12808. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12809. if(status == FALSE)
  12810. {
  12811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12812. {
  12813. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12814. }
  12815. else
  12816. {
  12817. SystemInitial = AC_QUANTITY;
  12818. }
  12819. }
  12820. }
  12821. int GetHeartBeatWithNOResponse(void)
  12822. {
  12823. return HeartBeatWithNOResponse;
  12824. }
  12825. void SetHeartBeatWithNOResponse(void)
  12826. {
  12827. HeartBeatWithNOResponse = 0;
  12828. }
  12829. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12830. /*
  12831. src 源字串的首地址(buf的地址)
  12832. separator 指定的分割字元
  12833. dest 接收子字串的陣列
  12834. num 分割後子字串的個數
  12835. */
  12836. char *pNext;
  12837. int count = 0;
  12838. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12839. return;
  12840. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12841. return;
  12842. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12843. while(pNext != NULL) {
  12844. *dest++ = pNext;
  12845. ++count;
  12846. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12847. }
  12848. *num = count;
  12849. }
  12850. int GetTransactionId(int gunindex, unsigned char idTag[])
  12851. {
  12852. char ch;
  12853. FILE *fptr1;
  12854. int temptransactionId;
  12855. char str[100]={0};
  12856. temptransactionId = 0;
  12857. /*------ Read the file ----------------*/
  12858. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12859. if (!fptr1)
  12860. {
  12861. printf(" File not found or unable to open the input file!!\n");
  12862. return temptransactionId;
  12863. }
  12864. ch=fgetc(fptr1);
  12865. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12866. rewind(fptr1);
  12867. if(ch!=EOF)
  12868. {
  12869. // printf("%c",ch);
  12870. while (fgets(str, 100, fptr1) != NULL)
  12871. {
  12872. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12873. if(str[0]=='\0')
  12874. {
  12875. break;
  12876. }
  12877. char *revbuf[8] = {0}; //存放分割後的子字串
  12878. int num = 0;//分割後子字串的個數
  12879. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12880. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12881. {
  12882. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12883. {
  12884. temptransactionId = atoi(revbuf[2]);
  12885. break;
  12886. }
  12887. }
  12888. }
  12889. }
  12890. fclose(fptr1);
  12891. /*------- End of reading ---------------*/
  12892. return temptransactionId;
  12893. }
  12894. void SetTransactionIdZero(int transactionId)
  12895. {
  12896. //TransactionId[gunindex] = 0;
  12897. char ch;
  12898. FILE *fptr1, *fptr2;
  12899. int temptransactionId = 0;
  12900. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12901. printf("\n\n Delete a specific line from a file :\n");
  12902. printf("-----------------------------------------\n");
  12903. //scanf("%s",fname);
  12904. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12905. if (!fptr1)
  12906. {
  12907. printf(" File not found or unable to open the input file!!\n");
  12908. return ;
  12909. }
  12910. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12911. if (!fptr2)
  12912. {
  12913. printf("Unable to open a temporary file to write!!\n");
  12914. fclose(fptr1);
  12915. return ;
  12916. }
  12917. ch=fgetc(fptr1);
  12918. //printf(" Now the content of the file %s is : \n",fname);
  12919. rewind(fptr1);
  12920. if(ch!=EOF)
  12921. {
  12922. // copy all contents to the temporary file except the specific line
  12923. while (fgets(str, 100, fptr1) != NULL)
  12924. {
  12925. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12926. if(str[0]=='\0')
  12927. {
  12928. break;
  12929. }
  12930. char *revbuf[8] = {0}; //存放分割後的子字串
  12931. int num = 0;//分割後子字串的個數
  12932. strcpy(strtemp, str);
  12933. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12934. if(revbuf[2][0] != '\0')
  12935. {
  12936. temptransactionId = atoi(revbuf[2]);
  12937. if(transactionId != temptransactionId)
  12938. {
  12939. fprintf(fptr2, "%s", strtemp);
  12940. }
  12941. }
  12942. }
  12943. }
  12944. fclose(fptr1);
  12945. fclose(fptr2);
  12946. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12947. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12948. /*------ Read the file ----------------*/
  12949. }
  12950. int InternetDisconnect(void)
  12951. {
  12952. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12953. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12954. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12955. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12956. }
  12957. void GetChargingProfileRequest(int gunindex)
  12958. {
  12959. mtrace();
  12960. //int connectorIdInt, durationInt;
  12961. //char chargingRateUnitStr[4]={0};
  12962. int tempdurationInt = 0;
  12963. int tempchargingProfileId = 0;
  12964. int tempstackLevel = 0;
  12965. int temptransactionId = 0;
  12966. float tempminChargingRateFloat = 0.0;
  12967. char tempchargingProfilePurposeStr[24]={0};
  12968. char tempchargingProfileKindStr[12]={0};
  12969. char temprecurrencyKindStr[8]={0};
  12970. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12971. char tempvalidToStr[28]={0};
  12972. int tempStartPeriodInt = 0;
  12973. float tempLimitInt = 0.0;//0.1;
  12974. int tempNumberPhasesInt=0;
  12975. char fname[200];
  12976. //char comfirmstr[20];
  12977. float MinChargingRate =0.0;
  12978. double diff_t;
  12979. struct tm tp;
  12980. FILE *fptr1;//, *fptr2;
  12981. int c = 0;
  12982. char * pch;
  12983. char *loc;
  12984. char sstr[200]={ 0 };
  12985. int n_chargingProfile = 0;
  12986. int n_SchedulePeriods = 0;
  12987. char SchedulePeriodList[10][200]={0};
  12988. char sLineWord[1600]={0};
  12989. char word[1000]={0};
  12990. int confirmPeriods = 0;
  12991. struct StructProfile ChargePointMaxProfile;
  12992. struct StructProfile TxDefaultProfile;
  12993. struct StructProfile TxProfile;
  12994. struct StructProfile TxDefaultProfiletemp[2]={0};
  12995. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12996. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12997. struct StructChargingProfile TxProfile_TEMP={0};
  12998. int TxDefaultProfileFileIsNull=FALSE;
  12999. int ChargePointMaxProfileIsNull=FALSE;
  13000. int TxProfileIsNull=FALSE;
  13001. // int CompositeSceduleIndex = 0;
  13002. char ChargePointMaxProfileScheduleStr[30]={0};
  13003. char TxDefaultProfileScheduleStr[30]={0};
  13004. char TxProfileScheduleStr[30]={0};
  13005. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13006. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13007. memset(&TxProfile,0,sizeof(struct StructProfile));
  13008. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13009. DEBUG_INFO("GetChargingProfileRequest\n");
  13010. //*****************************ChargePointMaxProfile******************************************/
  13011. strcpy(fname, ChargePointMaxProfile_JSON);
  13012. ChargePointMaxProfileIsNull=TRUE;
  13013. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13014. {
  13015. fptr1 = fopen(fname, "r");
  13016. int c;
  13017. c = fgetc(fptr1);
  13018. //DEBUG_INFO("c:%d\n",c);
  13019. rewind(fptr1);
  13020. if(c == EOF)
  13021. {
  13022. DEBUG_INFO("\n End of file reached.");
  13023. ChargePointMaxProfileIsNull=TRUE;
  13024. fclose(fptr1);
  13025. }
  13026. else
  13027. {
  13028. ChargePointMaxProfileIsNull=FALSE;
  13029. while(fscanf(fptr1, "%s", word) != EOF)
  13030. {
  13031. if(strcmp(word, "chargingProfileId") == 0)
  13032. {
  13033. n_chargingProfile = n_chargingProfile + 1;
  13034. }
  13035. }
  13036. rewind(fptr1);
  13037. //search Charging Profile Element
  13038. int i = 0;
  13039. int j = 0;
  13040. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13041. //***********chargingProfileId**************/
  13042. c = 0;
  13043. loc = strstr(sLineWord, "chargingProfileId");
  13044. //DEBUG_INFO("loc=%s\n",loc);
  13045. memset(sstr ,0, sizeof(sstr) );
  13046. if(loc != NULL)
  13047. {
  13048. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13049. {
  13050. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13052. c++;
  13053. }
  13054. sstr[c] = '\0';
  13055. tempchargingProfileId = atoi(sstr);
  13056. }
  13057. else
  13058. {
  13059. tempchargingProfileId = 0;
  13060. }
  13061. //***********stackLevel**************/
  13062. c = 0;
  13063. loc = strstr(sLineWord, "stackLevel");
  13064. //DEBUG_INFO("loc=%s\n",loc);
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. if(loc != NULL)
  13067. {
  13068. while (loc[2+strlen("stackLevel")+c] != '\"')
  13069. {
  13070. sstr[c] = loc[2+strlen("stackLevel")+c];
  13071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13072. c++;
  13073. }
  13074. sstr[c] = '\0';
  13075. tempstackLevel = atoi(sstr);
  13076. }
  13077. else
  13078. {
  13079. tempstackLevel = 0;
  13080. }
  13081. //***********chargingProfilePurpose **************/
  13082. c = 0;
  13083. loc = strstr(sLineWord, "chargingProfilePurpose");
  13084. //DEBUG_INFO("loc=%s\n",loc);
  13085. memset(sstr ,0, sizeof(sstr) );
  13086. if(loc != NULL)
  13087. {
  13088. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13089. {
  13090. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13091. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13092. c++;
  13093. }
  13094. sstr[c] = '\0';
  13095. strcpy(tempchargingProfilePurposeStr,sstr);
  13096. }
  13097. else
  13098. {
  13099. strcpy(tempchargingProfilePurposeStr,"");
  13100. }
  13101. //***********chargingProfileKind **************/
  13102. c = 0;
  13103. loc = strstr(sLineWord, "chargingProfileKind");
  13104. //DEBUG_INFO("loc=%s\n",loc);
  13105. memset(sstr ,0, sizeof(sstr) );
  13106. if(loc != NULL)
  13107. {
  13108. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13109. {
  13110. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13112. c++;
  13113. }
  13114. sstr[c] = '\0';
  13115. strcpy(tempchargingProfileKindStr,sstr);
  13116. }
  13117. else
  13118. {
  13119. strcpy(tempchargingProfileKindStr,"");
  13120. }
  13121. //***********recurrencyKind **************/
  13122. c = 0;
  13123. loc = strstr(sLineWord, "recurrencyKind");
  13124. //DEBUG_INFO("loc=%s\n",loc);
  13125. memset(sstr ,0, sizeof(sstr) );
  13126. if(loc != NULL)
  13127. {
  13128. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13129. {
  13130. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13132. c++;
  13133. }
  13134. sstr[c] = '\0';
  13135. strcpy(temprecurrencyKindStr,sstr);
  13136. }
  13137. else
  13138. {
  13139. strcpy(temprecurrencyKindStr,"");
  13140. }
  13141. //***********validFrom**************/
  13142. c = 0;
  13143. loc = strstr(sLineWord, "validFrom");
  13144. //DEBUG_INFO("loc=%s\n",loc);
  13145. memset(sstr ,0, sizeof(sstr) );
  13146. if(loc != NULL)
  13147. {
  13148. while (loc[3+strlen("validFrom")+c] != '\"')
  13149. {
  13150. sstr[c] = loc[3+strlen("validFrom")+c];
  13151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13152. c++;
  13153. }
  13154. sstr[c] = '\0';
  13155. strcpy(tempvalidFromStr,sstr);
  13156. }
  13157. else
  13158. {
  13159. strcpy(tempvalidFromStr,"");
  13160. }
  13161. //***********validTo **************/
  13162. c = 0;
  13163. loc = strstr(sLineWord, "validTo");
  13164. //DEBUG_INFO("loc=%s\n",loc);
  13165. memset(sstr ,0, sizeof(sstr) );
  13166. if(loc != NULL)
  13167. {
  13168. while (loc[3+strlen("validTo")+c] != '\"')
  13169. {
  13170. sstr[c] = loc[3+strlen("validTo")+c];
  13171. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13172. c++;
  13173. }
  13174. sstr[c] = '\0';
  13175. strcpy(tempvalidToStr,sstr);
  13176. }
  13177. else
  13178. {
  13179. strcpy(tempvalidToStr,"");
  13180. }
  13181. //***********validFrom**************/
  13182. c = 0;
  13183. loc = strstr(sLineWord, "validFrom");
  13184. if(loc != NULL)
  13185. {
  13186. memset(sstr ,0, sizeof(sstr) );
  13187. while (loc[3+strlen("validFrom")+c] != '\"')
  13188. {
  13189. sstr[c] = loc[3+strlen("validFrom")+c];
  13190. c++;
  13191. }
  13192. sstr[c] = '\0';
  13193. strcpy(tempvalidFromStr,sstr);
  13194. }
  13195. else
  13196. {
  13197. strcpy(tempvalidFromStr,"");
  13198. }
  13199. //***********validTo **************/
  13200. c = 0;
  13201. loc = strstr(sLineWord, "validTo");
  13202. if(loc != NULL)
  13203. {
  13204. memset(sstr ,0, sizeof(sstr) );
  13205. while (loc[3+strlen("validTo")+c] != '\"')
  13206. {
  13207. sstr[c] = loc[3+strlen("validTo")+c];
  13208. c++;
  13209. }
  13210. sstr[c] = '\0';
  13211. strcpy(tempvalidToStr,sstr);
  13212. }
  13213. else
  13214. {
  13215. strcpy(tempvalidToStr,"");
  13216. }
  13217. //***********duration**************/
  13218. c = 0;
  13219. loc = strstr(sLineWord, "duration");
  13220. if(loc != NULL)
  13221. {
  13222. memset(sstr ,0, sizeof(sstr) );
  13223. while (loc[2+strlen("duration")+c] != ',')
  13224. {
  13225. sstr[c] = loc[2+strlen("duration")+c];
  13226. c++;
  13227. }
  13228. sstr[c] = '\0';
  13229. tempdurationInt = atoi(sstr);
  13230. }
  13231. else
  13232. {
  13233. tempdurationInt = 0;
  13234. }
  13235. //**********startSchedule**********/
  13236. c = 0;
  13237. loc = strstr(sLineWord, "startSchedule");
  13238. memset(sstr ,0, sizeof(sstr) );
  13239. while (loc[3+strlen("startSchedule")+c] != '\"')
  13240. {
  13241. sstr[c] = loc[3+strlen("startSchedule")+c];
  13242. c++;
  13243. }
  13244. sstr[c] = '\0';
  13245. strcpy(tempstartScheduleStr, sstr);
  13246. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13247. //**********chargingRateUnit**********/
  13248. c = 0;
  13249. loc = strstr(sLineWord, "chargingRateUnit");
  13250. memset(sstr ,0, sizeof(sstr) );
  13251. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13252. {
  13253. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13254. c++;
  13255. }
  13256. sstr[c] = '\0';
  13257. strcpy(tempchargingRateUnitStr, sstr);
  13258. //**********minChargingRate*******/
  13259. c = 0;
  13260. loc = strstr(sLineWord, "minChargingRate");
  13261. if(loc != NULL)
  13262. {
  13263. memset(sstr ,0, sizeof(sstr) );
  13264. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13265. {
  13266. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13267. c++;
  13268. }
  13269. sstr[c] = '\0';
  13270. tempminChargingRateFloat = atof(sstr);
  13271. }
  13272. else
  13273. {
  13274. tempminChargingRateFloat = 0.0;
  13275. }
  13276. //
  13277. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13278. tp.tm_isdst = -1;
  13279. time_t utc = mktime(&tp);
  13280. time_t t = time(NULL);
  13281. diff_t = difftime(t, utc);
  13282. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13283. //parsing strings to words
  13284. i = 0;
  13285. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13286. loc = loc+3+strlen("chargingSchedulePeriod");
  13287. pch = strtok(loc ,"{");
  13288. while (pch != NULL)
  13289. {
  13290. strcpy(SchedulePeriodList[i], pch);
  13291. pch = strtok (NULL, "{");
  13292. i = i + 1;
  13293. }
  13294. n_SchedulePeriods = i;
  13295. for(int i=0;i<n_SchedulePeriods;i++)
  13296. {
  13297. //*************startPeriod****************/
  13298. c = 0;
  13299. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13300. memset(sstr ,0, sizeof(sstr) );
  13301. while (loc[strlen("startPeriod")+2+c] != ',')
  13302. {
  13303. sstr[c] = loc[strlen("startPeriod")+2+c];
  13304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13305. c++;
  13306. }
  13307. sstr[c] = '\0';
  13308. tempStartPeriodInt = atoi(sstr);
  13309. //*************limit****************/
  13310. c = 0;
  13311. loc = strstr(SchedulePeriodList[i], "limit");
  13312. memset(sstr ,0, sizeof(sstr) );
  13313. while (loc[strlen("limit")+2+c] != ',')
  13314. {
  13315. sstr[c] = loc[strlen("limit")+2+c];
  13316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13317. c++;
  13318. }
  13319. sstr[c] = '\0';
  13320. tempLimitInt = atof(sstr);
  13321. //*************numberPhases****************/
  13322. c = 0;
  13323. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13324. memset(sstr ,0, sizeof(sstr) );
  13325. while (loc[strlen("numberPhases")+2+c] != '}')
  13326. {
  13327. sstr[c] = loc[strlen("numberPhases")+2+c];
  13328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13329. c++;
  13330. }
  13331. sstr[c] = '\0';
  13332. tempNumberPhasesInt = atoi(sstr);
  13333. if(j == 0)
  13334. {
  13335. ChargePointMaxProfile.Duration = tempdurationInt;
  13336. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13337. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13338. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13339. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13340. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13341. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13342. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13343. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13344. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13345. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13346. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13347. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13348. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13349. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13350. }
  13351. }
  13352. if(MinChargingRate < tempminChargingRateFloat)
  13353. {
  13354. MinChargingRate = tempminChargingRateFloat;
  13355. }
  13356. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13357. if(confirmPeriods < n_SchedulePeriods)
  13358. {
  13359. confirmPeriods = n_SchedulePeriods;
  13360. }
  13361. j = j + 1;
  13362. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13363. fclose(fptr1);
  13364. }// end else
  13365. }// the end of access file ChargePointMaxProfile
  13366. //****************************TxDefaultProfile************************************************/
  13367. #if 0
  13368. switch(gunindex + 1)
  13369. {
  13370. case 0:
  13371. strcpy(fname, TxDefaultProfile_0_JSON );
  13372. break;
  13373. case 1:
  13374. strcpy(fname, TxDefaultProfile_1_JSON );
  13375. break;
  13376. case 2:
  13377. strcpy(fname, TxDefaultProfile_2_JSON );
  13378. break;
  13379. default:
  13380. strcpy(fname, TxDefaultProfile_1_JSON );
  13381. break;
  13382. }
  13383. #endif
  13384. memset(fname, 0, sizeof fname);
  13385. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13386. TxDefaultProfileFileIsNull=TRUE;
  13387. if((access(fname,F_OK))!=-1)
  13388. {
  13389. fptr1 = fopen(fname, "r");
  13390. c = 0;
  13391. c = fgetc(fptr1);
  13392. //DEBUG_INFO("c:%d\n",c);
  13393. rewind(fptr1);
  13394. if(c == EOF)
  13395. {
  13396. DEBUG_INFO("\n End of file reached.");
  13397. TxDefaultProfileFileIsNull=TRUE;
  13398. fclose(fptr1);
  13399. }
  13400. else
  13401. {
  13402. TxDefaultProfileFileIsNull=FALSE;
  13403. while(fscanf(fptr1, "%s", word) != EOF)
  13404. {
  13405. if(strcmp(word, "chargingProfileId") == 0)
  13406. {
  13407. n_chargingProfile = n_chargingProfile + 1;
  13408. }
  13409. }
  13410. rewind(fptr1);
  13411. //search Charging Profile Element
  13412. int i = 0;
  13413. int j = 0;
  13414. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13415. {
  13416. #if 0
  13417. //***********connectorId****************/
  13418. c = 0;
  13419. loc = strstr(sLineWord, "connectorId");
  13420. memset(sstr ,0, sizeof(sstr) );
  13421. while (loc[strlen("connectorId")+2+c] != ',')
  13422. {
  13423. sstr[c] = loc[strlen("connectorId")+2+c];
  13424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13425. c++;
  13426. }
  13427. sstr[c] = '\0';
  13428. tempconnectorIdInt = atoi(sstr);
  13429. #endif
  13430. //***********chargingProfileId**************/
  13431. c = 0;
  13432. loc = strstr(sLineWord, "chargingProfileId");
  13433. //DEBUG_INFO("loc=%s\n",loc);
  13434. memset(sstr ,0, sizeof(sstr) );
  13435. if(loc != NULL)
  13436. {
  13437. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13438. {
  13439. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13440. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13441. c++;
  13442. }
  13443. sstr[c] = '\0';
  13444. tempchargingProfileId = atoi(sstr);
  13445. }
  13446. else
  13447. {
  13448. tempchargingProfileId = 0;
  13449. }
  13450. //***********stackLevel**************/
  13451. c = 0;
  13452. loc = strstr(sLineWord, "stackLevel");
  13453. //DEBUG_INFO("loc=%s\n",loc);
  13454. memset(sstr ,0, sizeof(sstr) );
  13455. if(loc != NULL)
  13456. {
  13457. while (loc[2+strlen("stackLevel")+c] != '\"')
  13458. {
  13459. sstr[c] = loc[2+strlen("stackLevel")+c];
  13460. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13461. c++;
  13462. }
  13463. sstr[c] = '\0';
  13464. tempstackLevel = atoi(sstr);
  13465. }
  13466. else
  13467. {
  13468. tempstackLevel = 0;
  13469. }
  13470. //***********chargingProfilePurpose **************/
  13471. c = 0;
  13472. loc = strstr(sLineWord, "chargingProfilePurpose");
  13473. //DEBUG_INFO("loc=%s\n",loc);
  13474. memset(sstr ,0, sizeof(sstr) );
  13475. if(loc != NULL)
  13476. {
  13477. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13478. {
  13479. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13481. c++;
  13482. }
  13483. sstr[c] = '\0';
  13484. strcpy(tempchargingProfilePurposeStr,sstr);
  13485. }
  13486. else
  13487. {
  13488. strcpy(tempchargingProfilePurposeStr,"");
  13489. }
  13490. //***********chargingProfileKind **************/
  13491. c = 0;
  13492. loc = strstr(sLineWord, "chargingProfileKind");
  13493. //DEBUG_INFO("loc=%s\n",loc);
  13494. memset(sstr ,0, sizeof(sstr) );
  13495. if(loc != NULL)
  13496. {
  13497. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13498. {
  13499. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13501. c++;
  13502. }
  13503. sstr[c] = '\0';
  13504. strcpy(tempchargingProfileKindStr,sstr);
  13505. }
  13506. else
  13507. {
  13508. strcpy(tempchargingProfileKindStr,"");
  13509. }
  13510. //***********recurrencyKind **************/
  13511. c = 0;
  13512. loc = strstr(sLineWord, "recurrencyKind");
  13513. //DEBUG_INFO("loc=%s\n",loc);
  13514. memset(sstr ,0, sizeof(sstr) );
  13515. if(loc != NULL)
  13516. {
  13517. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13518. {
  13519. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13521. c++;
  13522. }
  13523. sstr[c] = '\0';
  13524. strcpy(temprecurrencyKindStr,sstr);
  13525. }
  13526. else
  13527. {
  13528. strcpy(temprecurrencyKindStr,"");
  13529. }
  13530. //***********validFrom**************/
  13531. c = 0;
  13532. loc = strstr(sLineWord, "validFrom");
  13533. if(loc != NULL)
  13534. {
  13535. memset(sstr ,0, sizeof(sstr) );
  13536. while (loc[3+strlen("validFrom")+c] != '\"')
  13537. {
  13538. sstr[c] = loc[3+strlen("validFrom")+c];
  13539. c++;
  13540. }
  13541. sstr[c] = '\0';
  13542. strcpy(tempvalidFromStr,sstr);
  13543. }
  13544. else
  13545. {
  13546. strcpy(tempvalidFromStr,"");
  13547. }
  13548. //***********validTo **************/
  13549. c = 0;
  13550. loc = strstr(sLineWord, "validTo");
  13551. if(loc != NULL)
  13552. {
  13553. memset(sstr ,0, sizeof(sstr) );
  13554. while (loc[3+strlen("validTo")+c] != '\"')
  13555. {
  13556. sstr[c] = loc[3+strlen("validTo")+c];
  13557. c++;
  13558. }
  13559. sstr[c] = '\0';
  13560. strcpy(tempvalidToStr,sstr);
  13561. }
  13562. else
  13563. {
  13564. strcpy(tempvalidToStr,"");
  13565. }
  13566. //***********duration**************/
  13567. c = 0;
  13568. loc = strstr(sLineWord, "duration");
  13569. if(loc != NULL)
  13570. {
  13571. memset(sstr ,0, sizeof(sstr) );
  13572. while (loc[2+strlen("duration")+c] != ',')
  13573. {
  13574. sstr[c] = loc[2+strlen("duration")+c];
  13575. c++;
  13576. }
  13577. sstr[c] = '\0';
  13578. tempdurationInt = atoi(sstr);
  13579. }
  13580. else
  13581. {
  13582. tempdurationInt = 0;
  13583. }
  13584. //**********startSchedule**********/
  13585. c = 0;
  13586. loc = strstr(sLineWord, "startSchedule");
  13587. memset(sstr ,0, sizeof(sstr) );
  13588. while (loc[3+strlen("startSchedule")+c] != '\"')
  13589. {
  13590. sstr[c] = loc[3+strlen("startSchedule")+c];
  13591. c++;
  13592. }
  13593. sstr[c] = '\0';
  13594. strcpy(tempstartScheduleStr, sstr);
  13595. strcpy(TxDefaultProfileScheduleStr, sstr);
  13596. //**********chargingRateUnit**********/
  13597. c = 0;
  13598. loc = strstr(sLineWord, "chargingRateUnit");
  13599. memset(sstr ,0, sizeof(sstr) );
  13600. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13601. {
  13602. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13603. c++;
  13604. }
  13605. sstr[c] = '\0';
  13606. strcpy(tempchargingRateUnitStr, sstr);
  13607. //**********minChargingRate*******/
  13608. c = 0;
  13609. loc = strstr(sLineWord, "minChargingRate");
  13610. if(loc != NULL)
  13611. {
  13612. memset(sstr ,0, sizeof(sstr) );
  13613. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13614. {
  13615. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13616. c++;
  13617. }
  13618. sstr[c] = '\0';
  13619. tempminChargingRateFloat = atof(sstr);
  13620. }
  13621. else
  13622. {
  13623. tempminChargingRateFloat = 0.0;
  13624. }
  13625. //
  13626. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13627. tp.tm_isdst = -1;
  13628. time_t utc = mktime(&tp);
  13629. time_t t = time(NULL);
  13630. diff_t = difftime(t, utc);
  13631. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13632. //parsing strings to words
  13633. i = 0;
  13634. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13635. loc = loc+3+strlen("chargingSchedulePeriod");
  13636. pch = strtok(loc ,"{");
  13637. while (pch != NULL)
  13638. {
  13639. strcpy(SchedulePeriodList[i], pch);
  13640. pch = strtok (NULL, "{");
  13641. i = i + 1;
  13642. }
  13643. n_SchedulePeriods = i;
  13644. for(int i=0;i<n_SchedulePeriods;i++)
  13645. {
  13646. //*************startPeriod****************/
  13647. c = 0;
  13648. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13649. memset(sstr ,0, sizeof(sstr) );
  13650. while (loc[strlen("startPeriod")+2+c] != ',')
  13651. {
  13652. sstr[c] = loc[strlen("startPeriod")+2+c];
  13653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13654. c++;
  13655. }
  13656. sstr[c] = '\0';
  13657. tempStartPeriodInt = atoi(sstr);
  13658. //*************limit****************/
  13659. c = 0;
  13660. loc = strstr(SchedulePeriodList[i], "limit");
  13661. memset(sstr ,0, sizeof(sstr) );
  13662. while (loc[strlen("limit")+2+c] != ',')
  13663. {
  13664. sstr[c] = loc[strlen("limit")+2+c];
  13665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13666. c++;
  13667. }
  13668. sstr[c] = '\0';
  13669. tempLimitInt = atof(sstr);
  13670. //*************numberPhases****************/
  13671. c = 0;
  13672. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13673. memset(sstr ,0, sizeof(sstr) );
  13674. while (loc[strlen("numberPhases")+2+c] != '}')
  13675. {
  13676. sstr[c] = loc[strlen("numberPhases")+2+c];
  13677. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13678. c++;
  13679. }
  13680. sstr[c] = '\0';
  13681. tempNumberPhasesInt = atoi(sstr);
  13682. if(j == 0)
  13683. {
  13684. TxDefaultProfile.Duration = tempdurationInt;
  13685. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13686. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13687. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13688. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13689. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13690. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13691. TxDefaultProfile_TEMP.TransactionId = 0;
  13692. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13693. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13694. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13695. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13696. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13697. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13698. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13699. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13700. }
  13701. else
  13702. {
  13703. //other stack level charging Profile
  13704. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13705. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13706. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13707. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13708. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13709. }
  13710. }
  13711. if(MinChargingRate < tempminChargingRateFloat)
  13712. {
  13713. MinChargingRate = tempminChargingRateFloat;
  13714. }
  13715. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13716. if(confirmPeriods < n_SchedulePeriods)
  13717. confirmPeriods = n_SchedulePeriods;
  13718. j = j + 1;
  13719. }
  13720. fclose(fptr1);
  13721. //Stacking Charging Profiles
  13722. for(int l=0; l <(j-1) ;l++)
  13723. {
  13724. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13725. {
  13726. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13727. {
  13728. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13729. {
  13730. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13731. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13732. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13733. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13734. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13735. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13736. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13737. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13738. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13739. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13740. }
  13741. else
  13742. {
  13743. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13744. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13745. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13746. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13747. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13748. }
  13749. }
  13750. }
  13751. }//end of Stacking Charging Profiles
  13752. }// end else
  13753. }// the end of ACCESS TxDefaultProfile
  13754. //****************************TxProfile************************************************/
  13755. #if 0
  13756. switch(gunindex + 1)
  13757. {
  13758. case 0:
  13759. break;
  13760. case 1:
  13761. strcpy(fname, TxProfile_1_JSON );
  13762. break;
  13763. case 2:
  13764. strcpy(fname, TxProfile_2_JSON );
  13765. break;
  13766. default:
  13767. strcpy(fname, TxProfile_1_JSON );
  13768. break;
  13769. }
  13770. #endif
  13771. memset(fname, 0, sizeof fname);
  13772. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13773. TxProfileIsNull=TRUE;
  13774. if((access(fname,F_OK))!=-1)
  13775. {
  13776. fptr1 = fopen(fname, "r");
  13777. c = 0;
  13778. c = fgetc(fptr1);
  13779. //DEBUG_INFO("c:%d\n",c);
  13780. rewind(fptr1);
  13781. if(c == EOF)
  13782. {
  13783. DEBUG_INFO("\n End of file reached.");
  13784. TxProfileIsNull=TRUE;
  13785. fclose(fptr1);
  13786. }
  13787. else
  13788. {
  13789. TxProfileIsNull=FALSE;
  13790. while(fscanf(fptr1, "%s", word) != EOF)
  13791. {
  13792. if(strcmp(word, "chargingProfileId") == 0)
  13793. {
  13794. n_chargingProfile = n_chargingProfile + 1;
  13795. }
  13796. }
  13797. rewind(fptr1);
  13798. //search Charging Profile Element
  13799. int i= 0;
  13800. int j= 0;
  13801. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13802. #if 0
  13803. /***********connectorId****************/
  13804. c = 0;
  13805. loc = strstr(sLineWord, "connectorId");
  13806. memset(sstr ,0, sizeof(sstr) );
  13807. while (loc[strlen("connectorId")+2+c] != ',')
  13808. {
  13809. sstr[c] = loc[strlen("connectorId")+2+c];
  13810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13811. c++;
  13812. }
  13813. sstr[c] = '\0';
  13814. tempconnectorIdInt = atoi(sstr);
  13815. #endif
  13816. //***********chargingProfileId**************/
  13817. c = 0;
  13818. loc = strstr(sLineWord, "chargingProfileId");
  13819. memset(sstr ,0, sizeof(sstr) );
  13820. if(loc != NULL)
  13821. {
  13822. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13823. {
  13824. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13826. c++;
  13827. }
  13828. sstr[c] = '\0';
  13829. tempchargingProfileId = atoi(sstr);
  13830. }
  13831. else
  13832. {
  13833. tempchargingProfileId = 0;
  13834. }
  13835. //***********transactionId **************/
  13836. c = 0;
  13837. loc = strstr(sLineWord, "transactionId");
  13838. //DEBUG_INFO("loc=%s\n",loc);
  13839. memset(sstr ,0, sizeof(sstr) );
  13840. if(loc != NULL)
  13841. {
  13842. while (loc[2+strlen("transactionId")+c] != '\"')
  13843. {
  13844. sstr[c] = loc[2+strlen("transactionId")+c];
  13845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13846. c++;
  13847. }
  13848. sstr[c] = '\0';
  13849. temptransactionId = atoi(sstr);
  13850. }
  13851. else
  13852. {
  13853. temptransactionId = 0;
  13854. }
  13855. //***********stackLevel**************/
  13856. c = 0;
  13857. loc = strstr(sLineWord, "stackLevel");
  13858. //DEBUG_INFO("loc=%s\n",loc);
  13859. memset(sstr ,0, sizeof(sstr) );
  13860. if(loc != NULL)
  13861. {
  13862. while (loc[2+strlen("stackLevel")+c] != '\"')
  13863. {
  13864. sstr[c] = loc[2+strlen("stackLevel")+c];
  13865. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13866. c++;
  13867. }
  13868. sstr[c] = '\0';
  13869. tempstackLevel = atoi(sstr);
  13870. }
  13871. else
  13872. {
  13873. tempstackLevel = 0;
  13874. }
  13875. //***********chargingProfilePurpose **************/
  13876. c = 0;
  13877. loc = strstr(sLineWord, "chargingProfilePurpose");
  13878. //DEBUG_INFO("loc=%s\n",loc);
  13879. memset(sstr ,0, sizeof(sstr) );
  13880. if(loc != NULL)
  13881. {
  13882. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13883. {
  13884. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13886. c++;
  13887. }
  13888. sstr[c] = '\0';
  13889. strcpy(tempchargingProfilePurposeStr,sstr);
  13890. }
  13891. else
  13892. {
  13893. strcpy(tempchargingProfilePurposeStr,"");
  13894. }
  13895. //***********chargingProfileKind **************/
  13896. c = 0;
  13897. loc = strstr(sLineWord, "chargingProfileKind");
  13898. //DEBUG_INFO("loc=%s\n",loc);
  13899. memset(sstr ,0, sizeof(sstr) );
  13900. if(loc != NULL)
  13901. {
  13902. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13903. {
  13904. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13906. c++;
  13907. }
  13908. sstr[c] = '\0';
  13909. strcpy(tempchargingProfileKindStr,sstr);
  13910. }
  13911. else
  13912. {
  13913. strcpy(tempchargingProfileKindStr,"");
  13914. }
  13915. //***********recurrencyKind **************/
  13916. c = 0;
  13917. loc = strstr(sLineWord, "recurrencyKind");
  13918. //DEBUG_INFO("loc=%s\n",loc);
  13919. memset(sstr ,0, sizeof(sstr) );
  13920. if(loc != NULL)
  13921. {
  13922. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13923. {
  13924. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13926. c++;
  13927. }
  13928. sstr[c] = '\0';
  13929. strcpy(temprecurrencyKindStr,sstr);
  13930. }
  13931. else
  13932. {
  13933. strcpy(temprecurrencyKindStr,"");
  13934. }
  13935. //***********validFrom**************/
  13936. c = 0;
  13937. loc = strstr(sLineWord, "validFrom");
  13938. if(loc != NULL)
  13939. {
  13940. memset(sstr ,0, sizeof(sstr) );
  13941. while (loc[3+strlen("validFrom")+c] != '\"')
  13942. {
  13943. sstr[c] = loc[3+strlen("validFrom")+c];
  13944. c++;
  13945. }
  13946. sstr[c] = '\0';
  13947. strcpy(tempvalidFromStr,sstr);
  13948. }
  13949. else
  13950. {
  13951. strcpy(tempvalidFromStr,"");
  13952. }
  13953. //***********validTo**************/
  13954. c = 0;
  13955. loc = strstr(sLineWord, "validTo");
  13956. if(loc != NULL)
  13957. {
  13958. memset(sstr ,0, sizeof(sstr) );
  13959. while (loc[3+strlen("validTo")+c] != '\"')
  13960. {
  13961. sstr[c] = loc[3+strlen("validTo")+c];
  13962. c++;
  13963. }
  13964. sstr[c] = '\0';
  13965. strcpy(tempvalidToStr,sstr);
  13966. }
  13967. else
  13968. {
  13969. strcpy(tempvalidToStr,"");
  13970. }
  13971. //***********duration**************/
  13972. c = 0;
  13973. loc = strstr(sLineWord, "duration");
  13974. //DEBUG_INFO("loc=%s\n",loc);
  13975. memset(sstr ,0, sizeof(sstr) );
  13976. if(loc != NULL)
  13977. {
  13978. while (loc[2+strlen("duration")+c] != '\"')
  13979. {
  13980. sstr[c] = loc[2+strlen("duration")+c];
  13981. c++;
  13982. }
  13983. sstr[c] = '\0';
  13984. tempdurationInt = atoi(sstr);
  13985. }
  13986. else
  13987. {
  13988. tempdurationInt = 0;
  13989. }
  13990. //**********startSchedule**********/
  13991. c = 0;
  13992. loc = strstr(sLineWord, "startSchedule");
  13993. memset(sstr ,0, sizeof(sstr) );
  13994. while (loc[3+strlen("startSchedule")+c] != '\"')
  13995. {
  13996. sstr[c] = loc[3+strlen("startSchedule")+c];
  13997. c++;
  13998. }
  13999. sstr[c] = '\0';
  14000. strcpy(tempstartScheduleStr, sstr);
  14001. strcpy(TxProfileScheduleStr, sstr);
  14002. //**********chargingRateUnit**********/
  14003. c = 0;
  14004. loc = strstr(sLineWord, "chargingRateUnit");
  14005. memset(sstr ,0, sizeof(sstr) );
  14006. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14007. {
  14008. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14009. c++;
  14010. }
  14011. sstr[c] = '\0';
  14012. strcpy(tempchargingRateUnitStr, sstr);
  14013. //**********minChargingRate*******/
  14014. c = 0;
  14015. loc = strstr(sLineWord, "minChargingRate");
  14016. if(loc != NULL)
  14017. {
  14018. memset(sstr ,0, sizeof(sstr) );
  14019. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14020. {
  14021. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14022. c++;
  14023. }
  14024. sstr[c] = '\0';
  14025. tempminChargingRateFloat = atof(sstr);
  14026. }
  14027. else
  14028. {
  14029. tempminChargingRateFloat = 0.0;
  14030. }
  14031. //
  14032. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14033. tp.tm_isdst = -1;
  14034. time_t utc = mktime(&tp);
  14035. time_t t = time(NULL);
  14036. diff_t = difftime(t, utc);
  14037. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14038. //parsing strings to words
  14039. i = 0;
  14040. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14041. loc = loc+3+strlen("chargingSchedulePeriod");
  14042. pch = strtok(loc ,"{");
  14043. while (pch != NULL)
  14044. {
  14045. strcpy(SchedulePeriodList[i], pch);
  14046. pch = strtok (NULL, "{");
  14047. i = i + 1;
  14048. }
  14049. n_SchedulePeriods = i;
  14050. for(int i=0;i<n_SchedulePeriods;i++)
  14051. {
  14052. //*************startPeriod****************/
  14053. c = 0;
  14054. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14055. memset(sstr ,0, sizeof(sstr) );
  14056. while (loc[strlen("startPeriod")+2+c] != ',')
  14057. {
  14058. sstr[c] = loc[strlen("startPeriod")+2+c];
  14059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14060. c++;
  14061. }
  14062. sstr[c] = '\0';
  14063. tempStartPeriodInt = atoi(sstr);
  14064. //*************limit****************/
  14065. c = 0;
  14066. loc = strstr(SchedulePeriodList[i], "limit");
  14067. memset(sstr ,0, sizeof(sstr) );
  14068. while (loc[strlen("limit")+2+c] != ',')
  14069. {
  14070. sstr[c] = loc[strlen("limit")+2+c];
  14071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14072. c++;
  14073. }
  14074. sstr[c] = '\0';
  14075. tempLimitInt = atof(sstr);
  14076. //*************numberPhases****************/
  14077. c = 0;
  14078. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14079. memset(sstr ,0, sizeof(sstr) );
  14080. while (loc[strlen("numberPhases")+2+c] != '}')
  14081. {
  14082. sstr[c] = loc[strlen("numberPhases")+2+c];
  14083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14084. c++;
  14085. }
  14086. sstr[c] = '\0';
  14087. tempNumberPhasesInt = atoi(sstr);
  14088. //TxProfile.Duration = durationInt;
  14089. TxProfile.TotalPeriod = n_SchedulePeriods;
  14090. TxProfile.Period[i].Limit = tempLimitInt;
  14091. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14092. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14093. }
  14094. if(MinChargingRate < tempminChargingRateFloat)
  14095. {
  14096. MinChargingRate = tempminChargingRateFloat;
  14097. }
  14098. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14099. if(confirmPeriods < n_SchedulePeriods)
  14100. confirmPeriods = n_SchedulePeriods;
  14101. if(j == 0)
  14102. {
  14103. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14104. TxProfile_TEMP.StackLevel = tempstackLevel;
  14105. TxProfile_TEMP.TransactionId = 0;
  14106. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14107. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14108. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14109. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14110. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14111. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14112. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14113. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14114. }
  14115. }
  14116. fclose(fptr1);
  14117. }
  14118. }// the end of ACCESS TxProfile
  14119. //-----------------------------------------------CompositeSchedule--------------------------//
  14120. int period=0;
  14121. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14122. {
  14123. //TxProfile
  14124. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14125. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14126. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14127. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14129. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14130. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14131. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14132. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14133. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14134. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14135. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14136. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14137. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14138. {
  14139. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14140. {
  14141. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14142. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14143. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14144. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14145. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14146. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14147. period = period + 1;
  14148. }
  14149. else
  14150. {
  14151. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14152. {
  14153. }
  14154. else
  14155. {
  14156. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14157. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14158. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14159. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14160. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14161. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14162. period = period + 1;
  14163. }
  14164. }
  14165. }
  14166. struct tm tp;
  14167. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14168. tp.tm_isdst = -1;
  14169. time_t utc = mktime(&tp);
  14170. time_t t = time(NULL);
  14171. double diff_f = difftime(t, utc);
  14172. int diff_i;// = (int)diff_f;
  14173. int quotient; // = diff_i / 86400;//86400 seconds/day
  14174. if(diff_f >= 0)
  14175. {
  14176. diff_i = (int)diff_f;
  14177. quotient = diff_i / 86400;//86400 seconds/day
  14178. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14179. {
  14180. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14181. {
  14182. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14183. {
  14184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14185. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14186. }
  14187. else
  14188. {
  14189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14190. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14191. }
  14192. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14193. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14194. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14195. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14196. period = period + 1;
  14197. }
  14198. }
  14199. }// end of if(diff_f >= 0)
  14200. }
  14201. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14202. {
  14203. //TxDefaultProfile
  14204. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14205. struct tm tp;
  14206. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14207. tp.tm_isdst = -1;
  14208. time_t utc = mktime(&tp);
  14209. time_t t = time(NULL);
  14210. double diff_f = difftime(t, utc);
  14211. int diff_i;// = (int)diff_f;
  14212. int quotient; // = diff_i / 86400;//86400 seconds/day
  14213. int remainder;
  14214. //---- Define StartSchedule----/
  14215. struct tm *gtime;
  14216. time_t now;
  14217. char buf[28];
  14218. //---Read the current system time---/
  14219. time(&now);
  14220. //---Convert the system time to GMT (now UTC)---/
  14221. gtime = gmtime(&now);
  14222. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14223. if(diff_f >= 0)
  14224. {
  14225. diff_i = (int)diff_f;
  14226. quotient = diff_i / 86400;//86400 seconds/day
  14227. remainder = diff_i % 86400;
  14228. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14229. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14230. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14233. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14234. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14235. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14236. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14237. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14238. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14239. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14240. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14241. {
  14242. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14243. {
  14244. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14245. {
  14246. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14247. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14248. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14249. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14250. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14251. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14252. period = period + 1;
  14253. }
  14254. else
  14255. {
  14256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14257. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14259. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14260. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14261. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14262. period = period + 1;
  14263. }
  14264. }
  14265. }
  14266. } // end of diff_f >= 0
  14267. }
  14268. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14269. {
  14270. //TxDefaultProfile
  14271. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14272. struct tm tp;
  14273. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14274. tp.tm_isdst = -1;
  14275. time_t utc = mktime(&tp);
  14276. time_t t = time(NULL);
  14277. double diff_f = difftime(t, utc);
  14278. int diff_i;// = (int)diff_f;
  14279. int quotient; // = diff_i / 86400;//86400 seconds/day
  14280. int remainder;
  14281. //---- Define StartSchedule----/
  14282. struct tm *gtime;
  14283. time_t now;
  14284. char buf[28];
  14285. //---Read the current system time---/
  14286. time(&now);
  14287. //---Convert the system time to GMT (now UTC)---/
  14288. gtime = gmtime(&now);
  14289. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14290. if(diff_f >= 0)
  14291. {
  14292. diff_i = (int)diff_f;
  14293. quotient = diff_i / 86400;//86400 seconds/day
  14294. remainder = diff_i % 86400;
  14295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14296. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14297. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14299. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14300. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14301. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14302. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14303. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14304. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14305. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14306. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14307. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14308. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14309. {
  14310. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14311. {
  14312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14313. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14314. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14315. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14316. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14317. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14318. period = period + 1;
  14319. }
  14320. }
  14321. } //end of diff_f >= 0
  14322. }
  14323. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14324. {
  14325. //ChargePointMaxProfile
  14326. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14327. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14328. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14329. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14330. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14332. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14333. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14334. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14335. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14336. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14339. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14340. {
  14341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14342. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14343. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14344. period = period + 1;
  14345. }
  14346. }
  14347. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14348. {
  14349. //TxProfile Daily
  14350. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14351. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14352. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14353. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14356. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14357. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14358. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14359. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14360. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14361. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14362. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14363. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14364. {
  14365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14367. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14368. }
  14369. }
  14370. confirmPeriods = period;
  14371. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14372. 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,"
  14373. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14374. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14375. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14376. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14377. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14378. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14379. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14380. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14381. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14382. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14384. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14385. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14415. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14416. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14417. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14418. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14419. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14420. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14421. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14422. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14423. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14425. }
  14426. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14427. {
  14428. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14429. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14430. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14431. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14432. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14433. }
  14434. int GetWebSocketPingInterval(void)
  14435. {
  14436. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14437. }
  14438. int GetInternetConn(void)
  14439. {
  14440. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14441. }
  14442. void LWS_Send(char * str)
  14443. {
  14444. //=====================================================
  14445. // Check InternetConn 0: disconnected, 1: connected
  14446. //====================================================
  14447. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14448. {
  14449. DEBUG_INFO("\n offline now !!!\n");
  14450. return;
  14451. }
  14452. pthread_mutex_lock(&lock);
  14453. memset(SendBuffer,0,SendBufLen);
  14454. sprintf((char *)SendBuffer, "%s", str);
  14455. pthread_mutex_unlock(&lock);
  14456. lws_callback_on_writable(wsi_client);
  14457. lws_service(context, 10000);//timeout_ms
  14458. }