MessageHandler.c 616 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044
  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. static int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. static int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. static int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. static int authorizeRetryTimes = 0; //number of Retry times
  124. //===============================
  125. // OCPP StartTransaction transactionId variables
  126. //===============================
  127. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  128. //===============================
  129. // OCPP other variables
  130. //===============================
  131. //int isUpdateRequest = FALSE;
  132. static int HeartBeatWaitTime = 10;
  133. static int FirstHeartBeat = 0;
  134. static int FirmwareStatusNotificationStatus = 3; // Idle
  135. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  136. static char CurrentChargingProfileScheduleStr[30]={0};
  137. //========================================
  138. // OCPP status/previous related variables
  139. //========================================
  140. static int GunStatusInterval = 10;
  141. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  142. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  143. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  144. static int GbPreviousSystemStatus[GB_QUANTITY];
  145. static int AcPreviousSystemStatus[AC_QUANTITY];
  146. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  147. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  148. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  149. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  150. static int TransactionMessageAttemptsValue = 0;
  151. static int TransactionMessageRetryIntervalValue = 0;
  152. static struct OCPPAuthLocalElemet
  153. {
  154. int listVersionInt;
  155. char idTagstr[20];
  156. char parentIdTag[20];
  157. char expiryDate[30];
  158. char idTagstatus[16];
  159. }idTagQuery;
  160. //=============================================
  161. // OCPP HeartBeat Response Not Receive Counts
  162. //============================================
  163. static int HeartBeatWithNOResponse = 0;
  164. static int HeartBeatCountPerHour = 0;
  165. extern struct lws *wsi_client;
  166. extern struct lws_context *context;
  167. extern unsigned char SendBuffer[4096];
  168. extern int SendBufLen;
  169. extern char *random_uuid( char buf[37] );
  170. extern void split(char **arr, char *str, const char *del);
  171. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  172. extern int GetTransactionQueueNum(void);
  173. extern pthread_mutex_t mutex1;
  174. extern struct Charger_Info Charger;
  175. extern sqlite3 *db;
  176. int TransactionMessageAttemptsGet(void);
  177. int TransactionMessageRetryIntervalGet(void);
  178. int GetOcppConnStatus(void);
  179. void SetOcppConnStatus(uint8_t status);
  180. int updateSetting(char *key, char *value);
  181. int setKeyValue(char *key, char *value);
  182. void OCPP_get_TableAuthlocalAllData(void);
  183. void processUnkownKey(void);
  184. struct StructOCPPMeterValue
  185. {
  186. unsigned char TimeStamp[28];
  187. struct StructSampledValue SampledValue[10];
  188. };
  189. struct ClientTime
  190. {
  191. unsigned int Heartbeat;
  192. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. unsigned int StartTransaction;
  194. unsigned int StopTransaction;
  195. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  196. }clientTime;
  197. typedef union
  198. {
  199. //Operations Initiated by Central System
  200. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  201. struct
  202. {
  203. //CsMsgValue[0]
  204. unsigned char StatusNotificationReq :1; //bit 0,
  205. unsigned char StatusNotificationConf :1; //bit 0,
  206. unsigned char :6; //bit 2~7
  207. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  208. }CpinitiateMsg;
  209. CpinitiateMsg cpinitateMsg;
  210. //==========================================
  211. // Init all Enumeration & Mapping String
  212. //==========================================
  213. /*ChargePointErrorCode*/
  214. typedef enum {
  215. ConnectorLockFailure,
  216. EVCommunicationError,
  217. GroundFailure,
  218. HighTemperature,
  219. InternalError,
  220. LocalListConflict,
  221. NoError,
  222. OtherError,
  223. OverCurrentFailure,
  224. OverVoltage,
  225. PowerMeterFailure,
  226. PowerSwitchFailure,
  227. ReaderFailure,
  228. ResetFailure,
  229. UnderVoltage,
  230. WeakSignal
  231. } ChargePointErrorCode;
  232. #if 0
  233. static char *ChargePointErrorCodeStr[] = {
  234. MACROSTR(ConnectorLockFailure),
  235. MACROSTR(EVCommunicationError),
  236. MACROSTR(GroundFailure),
  237. MACROSTR(HighTemperature),
  238. MACROSTR(InternalError),
  239. MACROSTR(LocalListConflict),
  240. MACROSTR(NoError),
  241. MACROSTR(OtherError),
  242. MACROSTR(OverCurrentFailure),
  243. MACROSTR(OverVoltage),
  244. MACROSTR(PowerMeterFailure),
  245. MACROSTR(PowerSwitchFailure),
  246. MACROSTR(ReaderFailure),
  247. MACROSTR(ResetFailure),
  248. MACROSTR(UnderVoltage),
  249. MACROSTR(WeakSignal)
  250. };
  251. #endif
  252. /*ChargePointStatus*/
  253. typedef enum {
  254. Available =0,
  255. Preparing,
  256. Charging,
  257. SuspendedEVSE,
  258. SuspendedEV,
  259. Finishing,
  260. Reserved,
  261. Unavailable,
  262. Faulted
  263. } ChargePointStatus;
  264. static char * ChargePointStatusStr[] = {
  265. MACROSTR(Available),
  266. MACROSTR(Preparing),
  267. MACROSTR(Charging),
  268. MACROSTR(SuspendedEVSE),
  269. MACROSTR(SuspendedEV),
  270. MACROSTR(Finishing),
  271. MACROSTR(Reserved),
  272. MACROSTR(Unavailable),
  273. MACROSTR(Faulted)
  274. };
  275. /*AvailabilityType*/
  276. typedef enum {
  277. RegistrationStatus_Accepted,
  278. RegistrationStatus_Pending,
  279. RegistrationStatus_Rejected
  280. } RegistrationStatus;
  281. static char *RegistrationStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Pending),
  284. MACROSTR(Rejected)
  285. };
  286. /*AvailabilityType*/
  287. typedef enum {
  288. Inoperative,
  289. Operative
  290. } AvailabilityType;
  291. static char *AvailabilityTypeStr[] = {
  292. MACROSTR(Inoperative),
  293. MACROSTR(Operative)
  294. };
  295. /*AvailabilityStatus*/
  296. typedef enum {
  297. Accepted,
  298. Rejected,
  299. Scheduled
  300. } AvailabilityStatus;
  301. static char *AvailabilityStatusStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Rejected),
  304. MACROSTR(Scheduled)
  305. };
  306. /*ConfigurationStatus*/
  307. typedef enum {
  308. ConfigurationStatus_Accepted,
  309. ConfigurationStatus_Rejected,
  310. RebootRequired,
  311. NotSupported
  312. } ConfigurationStatus;
  313. static char *ConfigurationStatusStr[] = {
  314. MACROSTR(Accepted),
  315. MACROSTR(Rejected),
  316. MACROSTR(RebootRequired),
  317. MACROSTR(NotSupported)
  318. };
  319. /*ClearCacheStatus*/
  320. typedef enum {
  321. ClearCacheStatus_Accepted,
  322. ClearCacheStatus_Rejected
  323. } ClearCacheStatus;
  324. static char *ClearCacheStatusStr[] = {
  325. MACROSTR(Accepted),
  326. MACROSTR(Rejected)
  327. };
  328. /*ChargingProfilePurposeType*/
  329. typedef enum {
  330. ChargePointMaxProfile,
  331. TxDefaultProfile,
  332. TxProfile
  333. } ChargingProfilePurposeType;
  334. static char *ChargingProfilePurposeTypeStr[] = {
  335. MACROSTR(ChargePointMaxProfile),
  336. MACROSTR(TxDefaultProfile),
  337. MACROSTR(TxProfile)
  338. };
  339. /*ChargingProfileStatus*/
  340. typedef enum {
  341. ChargingProfileStatus_Accepted,
  342. ChargingProfileStatus_Rejected,
  343. ChargingProfileStatus_NotSupported
  344. } ChargingProfileStatus;
  345. static char *ChargingProfileStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Rejected),
  348. MACROSTR(NotSupported)
  349. };
  350. /*ClearChargingProfileStatus*/
  351. typedef enum {
  352. ClearChargingProfileStatus_Accepted,
  353. ClearChargingProfileStatus_Unknown
  354. } ClearChargingProfileStatus;
  355. static char *ClearChargingProfileStatusStr[] = {
  356. MACROSTR(Accepted),
  357. MACROSTR(Unknown)
  358. };
  359. /*GetCompositeScheduleStatus*/
  360. typedef enum {
  361. GetCompositeScheduleStatus_Accepted,
  362. GetCompositeScheduleStatus_Rejected
  363. } GetCompositeScheduleStatus;
  364. static char *GetCompositeScheduleStatusStr[] = {
  365. MACROSTR(Accepted),
  366. MACROSTR(Rejected)
  367. };
  368. /*ChargingRateUnitType*/
  369. typedef enum {
  370. ChargingRateUnitType_W,
  371. ChargingRateUnitType_A
  372. } ChargingRateUnitType;
  373. /*AuthorizationStatus*/
  374. typedef enum {
  375. AuthorizationStatus_Accepted ,
  376. AuthorizationStatus_Blocked ,
  377. AuthorizationStatus_Expired ,
  378. AuthorizationStatus_Invalid ,
  379. AuthorizationStatus_ConcurrentTx
  380. } AuthorizationStatus;
  381. /*UpdateType*/
  382. typedef enum {
  383. Differential ,
  384. Full
  385. } UpdateType;
  386. static char *UpdateTypeStr[] = {
  387. MACROSTR(Differential),
  388. MACROSTR(Full)
  389. };
  390. /*UpdateStatus*/
  391. typedef enum {
  392. UpdateStatus_Accepted ,
  393. UpdateStatus_Failed ,
  394. UpdateStatus_NotSupported ,
  395. UpdateStatus_VersionMismatch
  396. } UpdateStatus;
  397. static char *UpdateStatusStr[] = {
  398. MACROSTR(Accepted),
  399. MACROSTR(Failed),
  400. MACROSTR(NotSupported),
  401. MACROSTR(VersionMismatch)
  402. };
  403. /*RemoteStartStopStatus*/
  404. typedef enum {
  405. RemoteStartStopStatus_Accepted,
  406. RemoteStartStopStatus_Rejected
  407. } RemoteStartStopStatus;
  408. static char *RemoteStartStopStatusStr[] = {
  409. MACROSTR(Accepted),
  410. MACROSTR(Rejected)
  411. };
  412. /*ReservationStatus*/
  413. typedef enum {
  414. ReservationStatus_Accepted,
  415. ReservationStatus_Faulted,
  416. ReservationStatus_Occupied,
  417. ReservationStatus_Rejected,
  418. ReservationStatus_Unavailable
  419. } ReservationStatus;
  420. static char *ReservationStatusStr[] = {
  421. MACROSTR(Accepted),
  422. MACROSTR(Faulted),
  423. MACROSTR(Occupied),
  424. MACROSTR(Rejected),
  425. MACROSTR(Unavailable)
  426. };
  427. /*ResetType*/
  428. typedef enum {
  429. Hard,
  430. Soft
  431. } ResetType;
  432. static char *ResetTypeStr[] = {
  433. MACROSTR(Hard),
  434. MACROSTR(Soft)
  435. };
  436. /*ResetStatus*/
  437. typedef enum {
  438. ResetStatus_Accepted,
  439. ResetStatus_Rejected
  440. } ResetStatus;
  441. static char *ResetStatusStr[] = {
  442. MACROSTR(Accepted),
  443. MACROSTR(Rejected)
  444. };
  445. /*DiagnosticsStatus*/
  446. typedef enum {
  447. DiagnosticsStatus_Idle,
  448. DiagnosticsStatus_Uploaded,
  449. DiagnosticsStatus_UploadFailed,
  450. DiagnosticsStatus_Uploading
  451. } DiagnosticsStatus;
  452. static char * DiagnosticsStatusStr[] = {
  453. MACROSTR(Idle),
  454. MACROSTR(Uploaded),
  455. MACROSTR(UploadFailed),
  456. MACROSTR(Uploading)
  457. };
  458. /*FirmwareStatus*/
  459. typedef enum {
  460. FirmwareStatus_Downloaded,
  461. FirmwareStatus_DownloadFailed,
  462. FirmwareStatus_Downloading,
  463. FirmwareStatus_Idle,
  464. FirmwareStatus_InstallationFailed,
  465. FirmwareStatus_Installing,
  466. FirmwareStatus_Installed
  467. } FirmwareStatus;
  468. static char * FirmwareStatusStr[] = {
  469. MACROSTR(Downloaded),
  470. MACROSTR(DownloadFailed),
  471. MACROSTR(Downloading),
  472. MACROSTR(Idle),
  473. MACROSTR(InstallationFailed),
  474. MACROSTR(Installing),
  475. MACROSTR(Installed)
  476. };
  477. /*MessageTrigger*/
  478. typedef enum {
  479. BootNotification,
  480. DiagnosticsStatusNotification,
  481. FirmwareStatusNotification,
  482. Heartbeat,
  483. MeterValues,
  484. StatusNotification
  485. } MessageTrigger;
  486. static char * MessageTriggerStr[] = {
  487. MACROSTR(BootNotification),
  488. MACROSTR(DiagnosticsStatusNotification),
  489. MACROSTR(FirmwareStatusNotification),
  490. MACROSTR(Heartbeat),
  491. MACROSTR(MeterValues),
  492. MACROSTR(StatusNotification)
  493. };
  494. /*TriggerMessageStatus*/
  495. typedef enum {
  496. TriggerMessageStatus_Accepted ,
  497. TriggerMessageStatus_Rejected ,
  498. TriggerMessageStatus_NotImplemented
  499. } TriggerMessageStatus;
  500. static char * TriggerMessageStatusStr[] = {
  501. MACROSTR(Accepted),
  502. MACROSTR(Rejected),
  503. MACROSTR(NotImplemented)
  504. };
  505. /*UnlockStatus*/
  506. typedef enum {
  507. Unlocked,
  508. UnlockFailed,
  509. UnlockStatus_NotSupported
  510. } UnlockStatus;
  511. static char * UnlockStatusStr[] = {
  512. MACROSTR(Unlocked),
  513. MACROSTR(UnlockFailed),
  514. MACROSTR(NotSupported)
  515. };
  516. /*StopTransactionReason*/
  517. typedef enum {
  518. EmergencyStop,
  519. EVDisconnected,
  520. HardReset,
  521. Local,
  522. Other,
  523. PowerLoss,
  524. Reboot,
  525. Remote,
  526. SoftReset,
  527. UnlockCommand,
  528. DeAuthorized
  529. } StopTransactionReason;
  530. #if 0
  531. static char * StopTransactionReasonStr[] = {
  532. MACROSTR(EmergencyStop),
  533. MACROSTR(EVDisconnected),
  534. MACROSTR(HardReset),
  535. MACROSTR(Local),
  536. MACROSTR(Other),
  537. MACROSTR(PowerLoss),
  538. MACROSTR(Reboot),
  539. MACROSTR(Remote),
  540. MACROSTR(SoftReset),
  541. MACROSTR(UnlockCommand),
  542. MACROSTR(DeAuthorized)
  543. };
  544. #endif
  545. /*CancelReservationStatus*/
  546. typedef enum {
  547. CancelReservationStatus_Accepted,
  548. CancelReservationStatus_Rejected
  549. } CancelReservationStatus;
  550. static char * CancelReservationStatusStr[] = {
  551. MACROSTR(Accepted),
  552. MACROSTR(Rejected)
  553. };
  554. /*ReadingContext*/
  555. typedef enum {
  556. ReadingContext_Interruption_Begin,
  557. ReadingContext_Interruption_End,
  558. ReadingContext_Other,
  559. ReadingContext_Sample_Clock,
  560. ReadingContext_Sample_Periodic ,
  561. ReadingContext_Transaction_Begin ,
  562. ReadingContext_Transaction_End,
  563. ReadingContext_Trigger
  564. } ReadingContext;
  565. static char * ReadingContextStr[] = {
  566. MACROSTR(Interruption.Begin),
  567. MACROSTR(Interruption.End),
  568. MACROSTR(Other),
  569. MACROSTR(Sample.Clock),
  570. MACROSTR(Sample.Periodic),
  571. MACROSTR(Transaction.Begin),
  572. MACROSTR(Transaction.End),
  573. MACROSTR(Trigger)
  574. };
  575. /*ValueFormat*/
  576. typedef enum {
  577. Raw,
  578. SignedData
  579. } ValueFormat;
  580. static char * ValueFormatStr[] = {
  581. MACROSTR(Raw),
  582. MACROSTR(SignedData)
  583. };
  584. /*Measurand*/
  585. typedef enum {
  586. Current_Export ,
  587. Current_Import,
  588. Current_Offered,
  589. Energy_Active_Export_Register,
  590. Energy_Active_Import_Register,
  591. Energy_Reactive_Export_Register,
  592. Energy_Reactive_Import_Register,
  593. Energy_Active_Export_Interval,
  594. Energy_Active_Import_Interval,
  595. Energy_Reactive_Export_Interval,
  596. Energy_Reactive_Import_Interval,
  597. Frequency,
  598. Power_Active_Export ,
  599. Power_Active_Import,
  600. Power_Factor,
  601. Power_Offered,
  602. Power_Reactive_Export,
  603. Power_Reactive_Import,
  604. RPM,
  605. SoC,
  606. Temperature ,
  607. Voltage
  608. } Measurand;
  609. static char * MeasurandStr[] = {
  610. MACROSTR(Current.Export),
  611. MACROSTR(Current.Import),
  612. MACROSTR(Current.Offered),
  613. MACROSTR(Energy.Active.Export.Register),
  614. MACROSTR(Energy.Active.Import.Register),
  615. MACROSTR(Energy.Reactive.Export.Register),
  616. MACROSTR(Energy.Reactive.Import.Register),
  617. MACROSTR(Energy.Active.Export.Interval),
  618. MACROSTR(Energy.Active.Import.Interval),
  619. MACROSTR(Energy.Reactive.Export.Interval),
  620. MACROSTR(Energy.Reactive.Import.Interval),
  621. MACROSTR(Frequency),
  622. MACROSTR(Power.Active.Export),
  623. MACROSTR(Power.Active.Import),
  624. MACROSTR(Power.Factor),
  625. MACROSTR(Power.Offered),
  626. MACROSTR(Power.Reactive.ExportMACROSTR),
  627. MACROSTR(Power.Reactive.Import),
  628. MACROSTR(RPM),
  629. MACROSTR(SoC),
  630. MACROSTR(Temperature),
  631. MACROSTR(Voltage)
  632. };
  633. /*Location*/
  634. typedef enum {
  635. Location_Body,
  636. Location_Cable,
  637. Location_EV,
  638. Location_Inlet ,
  639. Location_Outlet
  640. } Location;
  641. static char * LocationStr[] = {
  642. MACROSTR(Body),
  643. MACROSTR(Cable),
  644. MACROSTR(EV),
  645. MACROSTR(Inlet),
  646. MACROSTR(Outlet)
  647. };
  648. /*Phase*/
  649. typedef enum {
  650. L1,
  651. L2,
  652. L3,
  653. N,
  654. L1_N,
  655. L2_N,
  656. L3_N,
  657. L1_L2,
  658. L2_L3,
  659. L3_L1
  660. } Phase;
  661. static char * PhaseStr[] = {
  662. MACROSTR(L1),
  663. MACROSTR(L2),
  664. MACROSTR(L3),
  665. MACROSTR(N),
  666. MACROSTR(L1-N),
  667. MACROSTR(L2-N),
  668. MACROSTR(L3-N),
  669. MACROSTR(L1-L2),
  670. MACROSTR(L2-L3),
  671. MACROSTR(L3-L1)
  672. };
  673. /*UnitOfMeasure*/
  674. typedef enum {
  675. UnitOfMeasure_Wh,
  676. UnitOfMeasure_kWh ,
  677. UnitOfMeasure_varh ,
  678. UnitOfMeasure_kvarh ,
  679. UnitOfMeasure_W ,
  680. UnitOfMeasure_kW ,
  681. UnitOfMeasure_VA ,
  682. UnitOfMeasure_kVA ,
  683. UnitOfMeasure_var ,
  684. UnitOfMeasure_kvar ,
  685. UnitOfMeasure_A ,
  686. UnitOfMeasure_V ,
  687. UnitOfMeasure_Celsius ,
  688. UnitOfMeasure_Fahrenheit ,
  689. UnitOfMeasure_K ,
  690. UnitOfMeasure_Percent
  691. } UnitOfMeasure;
  692. static char * UnitOfMeasureStr[] = {
  693. MACROSTR(Wh),
  694. MACROSTR(kWh),
  695. MACROSTR(varh),
  696. MACROSTR(kvarh),
  697. MACROSTR(W),
  698. MACROSTR(kW),
  699. MACROSTR(VA),
  700. MACROSTR(kVA),
  701. MACROSTR(var),
  702. MACROSTR(kvar),
  703. MACROSTR(A),
  704. MACROSTR(V),
  705. MACROSTR(Celsius),
  706. MACROSTR(Fahrenheit),
  707. MACROSTR(K),
  708. MACROSTR(Percent)
  709. };
  710. #if 0
  711. /*Configuration enum*/
  712. enum CoreProfile {
  713. AllowOfflineTxForUnknownId=0,
  714. AuthorizationCacheEnabled,
  715. AuthorizeRemoteTxRequests,
  716. BlinkRepeat,
  717. ClockAlignedDataInterval,
  718. ConnectionTimeOut,
  719. GetConfigurationMaxKeys,
  720. HeartbeatInterval,
  721. LightIntensity,
  722. LocalAuthorizeOffline,
  723. LocalPreAuthorize,
  724. MaxEnergyOnInvalidId,
  725. MeterValuesAlignedData,
  726. MeterValuesAlignedDataMaxLength,
  727. MeterValuesSampledData,
  728. MeterValuesSampledDataMaxLength,
  729. MeterValueSampleInterval,
  730. MinimumStatusDuration,
  731. NumberOfConnectors,
  732. ResetRetries,
  733. ConnectorPhaseRotation,
  734. ConnectorPhaseRotationMaxLength,
  735. StopTransactionOnEVSideDisconnect,
  736. StopTransactionOnInvalidId,
  737. StopTxnAlignedData,
  738. StopTxnAlignedDataMaxLength,
  739. StopTxnSampledData,
  740. StopTxnSampledDataMaxLength,
  741. SupportedFeatureProfiles,
  742. SupportedFeatureProfilesMaxLength,
  743. TransactionMessageAttempts,
  744. TransactionMessageRetryInterval,
  745. UnlockConnectorOnEVSideDisconnect,
  746. WebSocketPingInterval,
  747. _CoreProfile_CNT
  748. };
  749. #endif
  750. enum LocalAuthListManagementProfile{
  751. LocalAuthListEnabled=0,
  752. LocalAuthListMaxLength,
  753. SendLocalListMaxLength,
  754. _LocalAuthListManagementProfile_CNT
  755. };
  756. enum ReservationProfile{
  757. ReserveConnectorZeroSupported
  758. };
  759. enum SmartChargingProfile{
  760. ChargeProfileMaxStackLevel,
  761. ChargingScheduleAllowedChargingRateUnit,
  762. ChargingScheduleMaxPeriods,
  763. ConnectorSwitch3to1PhaseSupported,
  764. MaxChargingProfilesInstalled
  765. };
  766. enum ChargerSystemStatus{
  767. ChargerSystemStatus_Booting,
  768. ChargerSystemStatus_Idle,
  769. ChargerSystemStatus_Authorizing,
  770. ChargerSystemStatus_Preparing,
  771. ChargerSystemStatus_Charging,
  772. ChargerSystemStatus_Terminating,
  773. ChargerSystemStatus_Alarm,
  774. ChargerSystemStatus_Fault
  775. };
  776. enum GetConfigurationKey {
  777. GetConfiguration_AllowOfflineTxForUnknownId=0,
  778. GetConfiguration_AuthorizationCacheEnabled,
  779. GetConfiguration_AuthorizeRemoteTxRequests,
  780. GetConfiguration_BlinkRepeat,
  781. GetConfiguration_ClockAlignedDataInterval,
  782. GetConfiguration_ConnectionTimeOut,
  783. GetConfiguration_GetConfigurationMaxKeys,
  784. GetConfiguration_HeartbeatInterval,
  785. GetConfiguration_LightIntensity,
  786. GetConfiguration_LocalAuthorizeOffline,
  787. GetConfiguration_LocalPreAuthorize,
  788. GetConfiguration_MaxEnergyOnInvalidId,
  789. GetConfiguration_MeterValuesAlignedData,
  790. GetConfiguration_MeterValuesAlignedDataMaxLength,
  791. GetConfiguration_MeterValuesSampledData,
  792. GetConfiguration_MeterValuesSampledDataMaxLength,
  793. GetConfiguration_MeterValueSampleInterval,
  794. GetConfiguration_MinimumStatusDuration,
  795. GetConfiguration_NumberOfConnectors,
  796. GetConfiguration_ResetRetries,
  797. GetConfiguration_ConnectorPhaseRotation,
  798. GetConfiguration_ConnectorPhaseRotationMaxLength,
  799. GetConfiguration_StopTransactionOnEVSideDisconnect,
  800. GetConfiguration_StopTransactionOnInvalidId,
  801. GetConfiguration_StopTxnAlignedData,
  802. GetConfiguration_StopTxnAlignedDataMaxLength,
  803. GetConfiguration_StopTxnSampledData,
  804. GetConfiguration_StopTxnSampledDataMaxLength,
  805. GetConfiguration_SupportedFeatureProfiles,
  806. GetConfiguration_SupportedFeatureProfilesMaxLength,
  807. GetConfiguration_TransactionMessageAttempts,
  808. GetConfiguration_TransactionMessageRetryInterval,
  809. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  810. GetConfiguration_WebSocketPingInterval,
  811. GetConfiguration_LocalAuthListEnabled,
  812. GetConfiguration_LocalAuthListMaxLength,
  813. GetConfiguration_SendLocalListMaxLength,
  814. GetConfiguration_ReserveConnectorZeroSupported,
  815. GetConfiguration_ChargeProfileMaxStackLevel,
  816. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  817. GetConfiguration_ChargingScheduleMaxPeriods,
  818. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  819. GetConfiguration_MaxChargingProfilesInstalled,
  820. };
  821. //GetConfiguration Array
  822. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  823. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  825. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  826. //==========================================
  827. // Init all share memory
  828. //==========================================
  829. int InitShareMemory()
  830. {
  831. int result = PASS;
  832. int MeterSMId;
  833. //creat ShmSysConfigAndInfo
  834. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmPsuData
  867. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmPsuData NG\n");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmPsuData NG\n");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. //creat ShmOCPP16Data
  884. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  885. {
  886. #ifdef SystemLogMessage
  887. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  888. #endif
  889. result = FAIL;
  890. }
  891. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  892. {
  893. #ifdef SystemLogMessage
  894. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  895. #endif
  896. result = FAIL;
  897. }
  898. else
  899. {}
  900. /****************************** For Initial Settings************************************************/
  901. #if 0
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. server_sign = FALSE;
  904. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  905. {
  906. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  907. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  910. }
  911. // Charger PRE_SYS_MODE
  912. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  913. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  914. clientTime.Heartbeat=time((time_t*)NULL);
  915. #endif
  916. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  918. // allocate Configuration memory address
  919. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  920. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  923. #if 0
  924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  925. {
  926. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  927. DEBUG_INFO("DC ...\n");
  928. }
  929. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  930. {
  931. SystemInitial = AC_QUANTITY;
  932. DEBUG_INFO("AC ...\n");
  933. }
  934. //Status / ConnectorPlugIn Setting
  935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  936. {
  937. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  938. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  939. }
  940. for (int index = 0; index < CCS_QUANTITY; index++)
  941. {
  942. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  943. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  944. }
  945. for (int index = 0; index < GB_QUANTITY; index++)
  946. {
  947. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  948. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  949. }
  950. for (int index = 0; index < AC_QUANTITY; index++)
  951. {
  952. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  953. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  954. }
  955. #endif
  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. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1012. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1013. {
  1014. printf("Heartbeat !!!\n");
  1015. //parameter for test
  1016. sendHeartbeatRequest(0);
  1017. //==============================================
  1018. // Reset Waiting Time
  1019. //==============================================
  1020. clientTime.Heartbeat=time((time_t*)NULL);
  1021. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1022. }
  1023. else if((server_sign == TRUE) &&(FirstHeartBeat == 0)) // Send First HeartBeat
  1024. {
  1025. printf("FirstHeartBeat !!!\n");
  1026. //parameter for test
  1027. sendHeartbeatRequest(0);
  1028. //==============================================
  1029. // Reset Waiting Time
  1030. //==============================================
  1031. clientTime.Heartbeat=time((time_t*)NULL);
  1032. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1033. }
  1034. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1035. {
  1036. //===============================
  1037. // CSU Trigger Reset Conf
  1038. //===============================
  1039. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1040. {
  1041. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1042. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1043. {
  1044. server_sign = FALSE;
  1045. }
  1046. }
  1047. //===============================
  1048. // CSU Trigger Authorize Request
  1049. //===============================
  1050. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1051. {
  1052. sendAuthorizeRequest(0);
  1053. authorizeRetryTimes = authorizeRetryTimes + 1;
  1054. if(authorizeRetryTimes < 3)
  1055. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1056. }
  1057. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1058. {
  1059. authorizeRetryTimes = 0;
  1060. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1061. server_sign = FALSE;
  1062. }
  1063. 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))
  1064. {
  1065. sendAuthorizeRequest(0);
  1066. }
  1067. //===============================
  1068. // CSU Trigger Smart Charging Profilw
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1071. {
  1072. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1073. GetChargingProfileRequest(gun_index);
  1074. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1075. }
  1076. //==============================================
  1077. // Charger start transaction
  1078. //==============================================
  1079. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1080. {
  1081. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1082. sendStartTransactionRequest(gun_index);
  1083. clientTime.StartTransaction = time((time_t*)NULL);
  1084. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1085. }
  1086. //==============================================
  1087. // Charger stop transaction
  1088. //==============================================
  1089. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1090. {
  1091. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1092. sendStopTransactionRequest(gun_index);
  1093. clientTime.StopTransaction = time((time_t*)NULL);
  1094. }
  1095. //==============================================
  1096. // Charger status report
  1097. //==============================================
  1098. /* Check Mode Change */
  1099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1100. {
  1101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1102. {
  1103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1104. {
  1105. 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]*/ )
  1106. {
  1107. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1108. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1109. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1110. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1111. statusModeChage[gun_index] = TRUE;
  1112. }
  1113. }
  1114. }
  1115. for (int index = 0; index < CCS_QUANTITY; index++)
  1116. {
  1117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1118. {
  1119. 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]*/ )
  1120. {
  1121. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1122. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1123. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1124. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1125. statusModeChage[gun_index] = TRUE;
  1126. }
  1127. }
  1128. }
  1129. for (int index = 0; index < GB_QUANTITY; index++)
  1130. {
  1131. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1132. {
  1133. 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]*/ )
  1134. {
  1135. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1136. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1137. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1138. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1139. statusModeChage[gun_index] = TRUE;
  1140. }
  1141. }
  1142. }
  1143. }
  1144. else //AC
  1145. {
  1146. for (int index = 0; index < AC_QUANTITY; index++)
  1147. {
  1148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1149. {
  1150. 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]*/ )
  1151. {
  1152. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1153. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1154. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1155. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1156. statusModeChage[gun_index] = TRUE;
  1157. }
  1158. }
  1159. }// END OF FOR
  1160. }// END OF ELSE
  1161. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1162. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1163. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1164. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1165. {
  1166. if(SystemInitial != 0)
  1167. SystemInitial = SystemInitial -1;
  1168. sendStatusNotificationRequest(gun_index);
  1169. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1170. statusModeChage[gun_index] = FALSE;
  1171. }
  1172. //==============================================
  1173. // Meter report
  1174. //==============================================
  1175. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1176. {
  1177. //check Transaction active
  1178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1179. {
  1180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1181. {
  1182. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1183. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1184. {
  1185. meterValueSend[gun_index] =1;
  1186. }
  1187. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1188. {
  1189. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1190. if((access(filenmae,F_OK))!=-1)
  1191. {
  1192. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1193. sprintf(str,"rm -f %s",filenmae);
  1194. system(str);
  1195. }
  1196. }
  1197. }// End for CHAdeMO
  1198. for (int index = 0; index < CCS_QUANTITY; index++)
  1199. {
  1200. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1201. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1202. {
  1203. meterValueSend[gun_index] =1;
  1204. }
  1205. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1206. {
  1207. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1208. if((access(filenmae,F_OK))!=-1)
  1209. {
  1210. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1211. sprintf(str,"rm -f %s",filenmae);
  1212. system(str);
  1213. }
  1214. }
  1215. } // End for CCS
  1216. for (int index = 0; index < GB_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for GB
  1234. }
  1235. else
  1236. {
  1237. for (int index = 0; index < AC_QUANTITY; index++)
  1238. {
  1239. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1240. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1241. {
  1242. meterValueSend[gun_index] =1;
  1243. }
  1244. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1245. {
  1246. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1247. if((access(filenmae,F_OK))!=-1)
  1248. {
  1249. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1250. sprintf(str,"rm -f %s",filenmae);
  1251. system(str);
  1252. }
  1253. }
  1254. }//End for AC
  1255. }//END OF ELSE
  1256. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1257. if(meterValueSend[gun_index] == 1)
  1258. sendMeterValuesRequest(gun_index);
  1259. }
  1260. //==============================================
  1261. // Check Connector reserved
  1262. //==============================================
  1263. //===============================
  1264. // Check if Reserve is expired
  1265. //===============================
  1266. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1267. {
  1268. double diff_t;
  1269. struct tm tp;
  1270. // current time
  1271. time_t t = time(NULL);
  1272. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1273. tp.tm_isdst = -1;
  1274. time_t utc = mktime(&tp);
  1275. diff_t = difftime(utc, t);
  1276. if(diff_t <= 0)
  1277. {
  1278. DEBUG_INFO("reserve expired !!! \n");
  1279. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1280. }
  1281. }//END OF Check if Reserve is expired
  1282. //==========================================
  1283. // csu trigger FirmwareStatusNotificationReq
  1284. //==========================================
  1285. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1286. {
  1287. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1288. }
  1289. //==========================================
  1290. // csu trigger CancelReservationConf
  1291. //==========================================
  1292. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1293. {
  1294. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1295. }
  1296. //==========================================
  1297. // csu trigger ChangeAvailabilityConf
  1298. //==========================================
  1299. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1300. {
  1301. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1302. }
  1303. //==========================================
  1304. // csu trigger UnlockConnectorConf
  1305. //==========================================
  1306. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1307. {
  1308. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1309. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1310. }
  1311. //==========================================
  1312. // csu trigger ReserveNowConf
  1313. //==========================================
  1314. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1315. {
  1316. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1317. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1318. }
  1319. //==========================================
  1320. // csu trigger DataTransferReq
  1321. //==========================================
  1322. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1323. {
  1324. sendDataTransferRequest(gun_index);
  1325. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1326. }
  1327. }
  1328. }
  1329. //==========================================
  1330. // send request routine
  1331. //==========================================
  1332. int sendAuthorizeRequest(int gun_index)
  1333. {
  1334. mtrace();
  1335. int result = FAIL;
  1336. char message[100]={0};
  1337. char guid[37];
  1338. char tempdata[65]={0};
  1339. DEBUG_INFO("sendAuthorizeRequest \n");
  1340. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1341. //Local Authorize
  1342. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1343. {
  1344. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1345. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1346. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1347. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1348. result = PASS;
  1349. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1350. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1351. authorizeRetryTimes = 0;
  1352. return result;
  1353. }
  1354. 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))||
  1355. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1356. {
  1357. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1358. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1359. {
  1360. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1361. {
  1362. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1363. }
  1364. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1365. {
  1366. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1367. }
  1368. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1371. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1372. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1373. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1374. authorizeRetryTimes = 0;
  1375. return result;
  1376. }
  1377. else
  1378. {
  1379. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1380. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1381. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1382. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1383. result = PASS;
  1384. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1385. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1386. authorizeRetryTimes = 0;
  1387. return result;
  1388. }
  1389. }
  1390. //initailize struct Authorize
  1391. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1392. //get data from shared memory
  1393. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1394. random_uuid(guid);
  1395. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1396. LWS_Send(message);
  1397. sprintf(tempdata, "Authorize,%d", gun_index);
  1398. if(hashmap_operation(0, guid, tempdata) == 1)
  1399. {
  1400. result = PASS;
  1401. DEBUG_ERROR("Authorize mapItem pass\n");
  1402. }
  1403. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1404. return result;
  1405. }
  1406. int sendBootNotificationRequest(void)
  1407. {
  1408. mtrace();
  1409. int result = FAIL;
  1410. char message[500]={0}, payload[700]={0};
  1411. char guid[37]={0};
  1412. char tempdata[65]={0};
  1413. int IsGunCharging = FALSE;
  1414. //check Transaction active
  1415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1416. {
  1417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1418. {
  1419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1420. {
  1421. IsGunCharging = TRUE;
  1422. }
  1423. }
  1424. for (int index = 0; index < CCS_QUANTITY; index++)
  1425. {
  1426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1427. {
  1428. IsGunCharging = TRUE;
  1429. }
  1430. }
  1431. for (int index = 0; index < GB_QUANTITY; index++)
  1432. {
  1433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1434. {
  1435. IsGunCharging = TRUE;
  1436. }
  1437. }
  1438. }
  1439. else
  1440. {
  1441. for (int index = 0; index < AC_QUANTITY; index++)
  1442. {
  1443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1444. {
  1445. IsGunCharging = TRUE;
  1446. }
  1447. }
  1448. }
  1449. if(IsGunCharging == TRUE)
  1450. {
  1451. server_sign = TRUE;
  1452. return result;
  1453. }
  1454. // Fill BootNotification fields
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1457. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1458. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1461. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1462. #if 0
  1463. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1464. ShmOCPP16Data->ChargeBoxId
  1465. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1466. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1467. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1468. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1469. ,ShmOCPP16Data->BootNotification.CpIccid
  1470. ,ShmOCPP16Data->BootNotification.CpImsi
  1471. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1472. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1473. #endif
  1474. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1475. ShmOCPP16Data->ChargeBoxId
  1476. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1477. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1478. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1479. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1480. ,ShmOCPP16Data->BootNotification.CpIccid
  1481. ,ShmOCPP16Data->BootNotification.CpImsi);
  1482. random_uuid(guid);
  1483. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1484. LWS_Send(message);
  1485. sprintf(tempdata, "BootNotification,0");
  1486. 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*/)
  1487. {
  1488. result = PASS;
  1489. }
  1490. memset(queuedata, 0, sizeof(queuedata));
  1491. strcpy(queuedata,message);
  1492. return result;
  1493. }
  1494. int sendDataTransferRequest(int gun_index)
  1495. {
  1496. mtrace();
  1497. char message[1000]={0};
  1498. char guid[37]={0};
  1499. char tempdata[65]={0};
  1500. int result = FAIL;
  1501. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1502. random_uuid(guid);
  1503. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1504. MESSAGE_TYPE_CALL,
  1505. guid,
  1506. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1507. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1508. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1509. LWS_Send(message);
  1510. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1511. 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*/)
  1512. {
  1513. result = PASS;
  1514. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1515. }
  1516. return result;
  1517. }
  1518. int sendDiagnosticsStatusNotificationRequest(char *status)
  1519. {
  1520. mtrace();
  1521. int result = FAIL;
  1522. char message[110]={0};
  1523. char guid[37]={0};
  1524. char tempdata[65]={0};
  1525. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1526. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1527. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1528. random_uuid(guid);
  1529. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1530. LWS_Send(message);
  1531. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1532. if(hashmap_operation(0, guid, tempdata) == 1)
  1533. {
  1534. result = PASS;
  1535. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1536. }
  1537. //#ifdef SystemLogMessage
  1538. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1539. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1540. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1541. //#endif
  1542. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1543. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1544. //record status
  1545. if(strcmp(status,"Idle")==0)
  1546. {
  1547. DiagnosticsStatusNotificationStatus = 0;
  1548. }
  1549. else if(strcmp(status,"Uploaded")==0)
  1550. {
  1551. DiagnosticsStatusNotificationStatus = 1;
  1552. }
  1553. else if(strcmp(status,"UploadFailed")==0)
  1554. {
  1555. DiagnosticsStatusNotificationStatus = 2;
  1556. }
  1557. else if(strcmp(status,"Uploading")==0)
  1558. {
  1559. DiagnosticsStatusNotificationStatus = 3;
  1560. }
  1561. return result;
  1562. }
  1563. int sendFirmwareStatusNotificationRequest(char *status)
  1564. {
  1565. mtrace();
  1566. int result = FAIL;
  1567. char message[110]={0};
  1568. char guid[37]={0};
  1569. char tempdata[65]={0};
  1570. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1571. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1572. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1573. random_uuid(guid);
  1574. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1575. LWS_Send(message);
  1576. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1577. 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*/)
  1578. {
  1579. result = PASS;
  1580. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1581. }
  1582. //#ifdef SystemLogMessage
  1583. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1584. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1585. //#endif
  1586. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1587. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1588. //record status
  1589. if(strcmp(status,"Downloaded")==0)
  1590. {
  1591. FirmwareStatusNotificationStatus = 0;
  1592. }
  1593. else if(strcmp(status,"DownloadFailed")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 1;
  1596. }
  1597. else if(strcmp(status,"Downloading")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 2;
  1600. }
  1601. else if(strcmp(status,"Idle")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 3;
  1604. }
  1605. else if(strcmp(status,"InstallationFailed")==0)
  1606. {
  1607. FirmwareStatusNotificationStatus = 4;
  1608. }
  1609. else if(strcmp(status,"Installing")==0)
  1610. {
  1611. FirmwareStatusNotificationStatus = 5;
  1612. }
  1613. else if(strcmp(status,"Installed")==0)
  1614. {
  1615. FirmwareStatusNotificationStatus = 6;
  1616. }
  1617. return result;
  1618. }
  1619. int sendHeartbeatRequest(int gun_index)
  1620. {
  1621. mtrace();
  1622. int result = FAIL;
  1623. char message[80]={0};
  1624. char guid[37]={0};
  1625. char tempdata[65]={0};
  1626. random_uuid(guid);
  1627. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1628. , MESSAGE_TYPE_CALL
  1629. , guid );
  1630. LWS_Send(message);
  1631. sprintf(tempdata, "Heartbeat,%d", 0);
  1632. 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*/)
  1633. {
  1634. result = PASS;
  1635. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1636. }
  1637. return result;
  1638. }
  1639. int sendStartTransactionRequest(int gun_index)
  1640. {
  1641. mtrace();
  1642. int result = FAIL;
  1643. char message[250]={0};
  1644. char guid[37]={0};
  1645. struct timeval tmnow;
  1646. struct tm *tm;
  1647. char buf[28];//, usec_buf[6];
  1648. char tempdata[65]={0};
  1649. DEBUG_INFO("sendStartTransactionRequest...");
  1650. gettimeofday(&tmnow, NULL);
  1651. time_t t;
  1652. t = time(NULL);
  1653. /*UTC time and date*/
  1654. tm = gmtime(&t);
  1655. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1656. #if 0 // remove temporally
  1657. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1658. strcat(buf,".");
  1659. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1660. strcat(buf,usec_buf);
  1661. #endif
  1662. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1663. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1664. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1665. // clear StartTransaction Response
  1666. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1667. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1668. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1669. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1671. {
  1672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1673. {
  1674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1675. {
  1676. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1677. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1678. }
  1679. }
  1680. for (int index = 0; index < CCS_QUANTITY; index++)
  1681. {
  1682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1683. {
  1684. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1685. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1686. }
  1687. }
  1688. for (int index = 0; index < GB_QUANTITY; index++)
  1689. {
  1690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1691. {
  1692. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1693. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1694. }
  1695. }
  1696. }
  1697. else
  1698. {
  1699. for (int index = 0; index < AC_QUANTITY; index++)
  1700. {
  1701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1702. {
  1703. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1704. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1705. }
  1706. }
  1707. }//END OF ELSE
  1708. random_uuid(guid);
  1709. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1710. , MESSAGE_TYPE_CALL
  1711. , guid
  1712. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1713. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1714. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1715. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1716. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1717. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1718. 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*/)
  1719. {
  1720. result = PASS;
  1721. }
  1722. strcpy(queuedata, message);
  1723. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1724. if(GetTransactionQueueNum() == 1)
  1725. {
  1726. LWS_Send(message);
  1727. }
  1728. #if 0
  1729. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1730. 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*/)
  1731. {
  1732. result = PASS;
  1733. }
  1734. strcpy(queuedata, message);
  1735. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1736. #endif
  1737. //#ifdef SystemLogMessage
  1738. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1739. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1740. //#endif
  1741. return result;
  1742. }
  1743. int sendStatusNotificationRequest(int gun_index)
  1744. {
  1745. mtrace();
  1746. int result = FAIL;
  1747. char message[600]={0};
  1748. char guid[37];
  1749. int currentStatus = 0;
  1750. struct timeval tmnow;
  1751. struct tm *tm;
  1752. char buf[28];//, usec_buf[6];
  1753. char tempdata[65]={0};
  1754. gettimeofday(&tmnow, NULL);
  1755. time_t t;
  1756. t = time(NULL);
  1757. /*UTC time and date*/
  1758. tm = gmtime(&t);
  1759. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1760. #if 0 // remove temporally
  1761. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1762. strcat(buf,".");
  1763. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1764. strcat(buf,usec_buf);
  1765. #endif
  1766. printf("%s",buf);
  1767. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1768. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1769. // it's option
  1770. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1771. /*
  1772. enum _SYSTEM_STATUS
  1773. {
  1774. S_BOOTING = 0,
  1775. S_IDLE, = 1
  1776. S_AUTHORIZING, =2
  1777. S_REASSIGN_CHECK, =3
  1778. S_REASSIGN, =4
  1779. S_PRECHARGE, =5
  1780. S_PREPARING_FOR_EV, =6
  1781. S_PREPARING_FOR_EVSE, =7
  1782. S_CHARGING, =8
  1783. S_TERMINATING, =9
  1784. S_COMPLETE, =10
  1785. S_ALARM, =11
  1786. S_FAULT =12
  1787. }
  1788. */
  1789. //check Transaction active
  1790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1791. {
  1792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1793. {
  1794. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1795. {
  1796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1797. {
  1798. currentStatus = 1; //OCPP Status: Preparing
  1799. }
  1800. else
  1801. {
  1802. currentStatus = 0; //OCPP Status: Available
  1803. }
  1804. }
  1805. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1806. {
  1807. currentStatus = 1; //OCPP Status: Preparing
  1808. }
  1809. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1810. {
  1811. currentStatus = 2; //OCPP Status: Charging
  1812. }
  1813. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1814. {
  1815. currentStatus = 5; //OCPP Status: Finishing
  1816. }
  1817. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1818. {
  1819. currentStatus = 4; //OCPP Status: SuspendedEV
  1820. }
  1821. 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
  1822. {
  1823. currentStatus = 7; //OCPP Status: Unavailable
  1824. }
  1825. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1826. {
  1827. currentStatus = 8; //OCPP Status: Faulted
  1828. }
  1829. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1830. {
  1831. currentStatus = 6; //OCPP Status: Reserved
  1832. }
  1833. }//end of for CHAdeMO_QUANTITY
  1834. for (int index = 0; index < CCS_QUANTITY; index++)
  1835. {
  1836. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1837. {
  1838. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1839. {
  1840. currentStatus = 1; //OCPP Status: Preparing
  1841. }
  1842. else
  1843. {
  1844. currentStatus = 0; //OCPP Status: Available
  1845. }
  1846. }
  1847. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1848. {
  1849. currentStatus = 1; //OCPP Status: Preparing
  1850. }
  1851. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1852. {
  1853. currentStatus = 2; //OCPP Status: Charging
  1854. }
  1855. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1856. {
  1857. currentStatus = 5; //OCPP Status: Finishing
  1858. }
  1859. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //S_TERMINATING ---> SuspendedEV
  1860. {
  1861. currentStatus = 4; //OCPP Status: SuspendedEV
  1862. }
  1863. 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
  1864. {
  1865. currentStatus = 7; //OCPP Status : Unavailable
  1866. }
  1867. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM ,S_FAULT ---> Faulted
  1868. {
  1869. currentStatus = 8; //OCPP Status: Faulted
  1870. }
  1871. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1872. {
  1873. currentStatus = 6; //OCPP Status: Reserved
  1874. }
  1875. }
  1876. for (int index = 0; index < GB_QUANTITY; index++)
  1877. {
  1878. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1879. {
  1880. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1881. {
  1882. currentStatus = 1; //OCPP Status: Preparing
  1883. }
  1884. else
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. }
  1889. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1890. {
  1891. currentStatus = 1; //OCPP Status: Preparing
  1892. }
  1893. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1894. {
  1895. currentStatus = 2; //OCPP Status: Charging
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1898. {
  1899. currentStatus = 5; //OCPP Status: Finishing
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1902. {
  1903. currentStatus = 4; //OCPP Status: SuspendedEV
  1904. }
  1905. 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
  1906. {
  1907. currentStatus = 7; //OCPP Status: Unavailable
  1908. }
  1909. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) )) //S_ALARM ,S_FAULT ---> Faulted
  1910. {
  1911. currentStatus = 8; //OCPP Status: Faulted
  1912. }
  1913. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1914. {
  1915. currentStatus = 6; //OCPP Status: Reserved
  1916. }
  1917. }
  1918. }
  1919. else
  1920. {
  1921. for (int index = 0; index < AC_QUANTITY; index++)
  1922. {
  1923. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1924. {
  1925. 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))
  1926. {
  1927. currentStatus = 1; //OCPP Status: Preparing
  1928. }
  1929. else
  1930. {
  1931. currentStatus = 0; //OCPP Status: Available
  1932. }
  1933. }
  1934. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1935. {
  1936. currentStatus = 1; //OCPP Status: Preparing
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1939. {
  1940. currentStatus = 2; //OCPP Status: Charging
  1941. }
  1942. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1943. {
  1944. currentStatus = 5; //OCPP Status: Finishing
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1947. {
  1948. currentStatus = 4; //OCPP Status: SuspendedEV
  1949. }
  1950. 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
  1951. {
  1952. currentStatus = 7; //OCPP Status: Unavailable
  1953. }
  1954. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1955. {
  1956. currentStatus = 8; //OCPP Status: Faulted
  1957. }
  1958. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1959. {
  1960. currentStatus = 6; //OCPP Status: Reserved
  1961. }
  1962. }//end of for AC_QUANTITY
  1963. }//END OF ELSE
  1964. //it's option
  1965. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1966. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1967. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1968. random_uuid(guid);
  1969. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1970. , MESSAGE_TYPE_CALL
  1971. , guid
  1972. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1973. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1974. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1975. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1976. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1977. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1978. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1979. LWS_Send(message);
  1980. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1981. 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*/)
  1982. {
  1983. //DEBUG_ERROR("statusNotification mapitem pass");
  1984. result = PASS;
  1985. }
  1986. return result;
  1987. }
  1988. int sendStopTransactionRequest(int gun_index)
  1989. {
  1990. mtrace();
  1991. int result = FAIL;
  1992. //char message[1500]={0};
  1993. char guid[37]={0};
  1994. char tempdata[65]={0};
  1995. //int idx_sample=0;
  1996. DEBUG_ERROR("sendStopTransactionRequest \n");
  1997. memset(queuedata, 0, sizeof(queuedata));
  1998. //ENERGY_ACTIVE_IMPORT_REGISTER
  1999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2000. {
  2001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2002. {
  2003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2004. {
  2005. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2006. }
  2007. }// END OF CHAdeMO_QUANTITY
  2008. for (int index = 0; index < CCS_QUANTITY; index++)
  2009. {
  2010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2011. {
  2012. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2013. }
  2014. }// END OF CCS_QUANTITY
  2015. for (int index = 0; index < GB_QUANTITY; index++)
  2016. {
  2017. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2018. {
  2019. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2020. }
  2021. }// END OF GB_QUANTITY
  2022. }
  2023. else
  2024. {
  2025. for (int index = 0; index < AC_QUANTITY; index++)
  2026. {
  2027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2028. {
  2029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2030. }
  2031. }// END OF AC_QUANTITY
  2032. }//END OF ELSE
  2033. //Stop Transaction Time
  2034. struct timeval tmnow;
  2035. struct tm *tm;
  2036. char buf[28];//, usec_buf[6];
  2037. gettimeofday(&tmnow, NULL);
  2038. time_t t;
  2039. t = time(NULL);
  2040. /*UTC time and date*/
  2041. tm = gmtime(&t);
  2042. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2044. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2045. random_uuid(guid);
  2046. /***********************************transactionData******************************************************/
  2047. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2049. //=================================
  2050. // Transaction_Begin
  2051. //=================================
  2052. // Energy.Active.Export.Interval
  2053. //idx_sample=0;
  2054. 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
  2055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2057. 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*/]);
  2058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2059. {
  2060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2061. }
  2062. else
  2063. {
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2065. }
  2066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2068. //=================================
  2069. // Transaction_End
  2070. //=================================
  2071. //Current.Export
  2072. //idx_sample=1;
  2073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2074. {
  2075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2076. {
  2077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2078. {
  2079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2080. }
  2081. }
  2082. for (int index = 0; index < CCS_QUANTITY; index++)
  2083. {
  2084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2085. {
  2086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2087. }
  2088. }
  2089. for (int index = 0; index < GB_QUANTITY; index++)
  2090. {
  2091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2092. {
  2093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2094. }
  2095. }
  2096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2097. }
  2098. else
  2099. {
  2100. for (int index = 0; index < AC_QUANTITY; index++)
  2101. {
  2102. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2103. {
  2104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2105. }
  2106. }
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2108. }// END FOR AC ELSE
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2112. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2115. //Energy.Active.Export.Interval
  2116. //idx_sample=2;
  2117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2118. {
  2119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2120. {
  2121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2122. {
  2123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2124. }
  2125. }
  2126. for (int index = 0; index < CCS_QUANTITY; index++)
  2127. {
  2128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2129. {
  2130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2131. }
  2132. }
  2133. for (int index = 0; index < GB_QUANTITY; index++)
  2134. {
  2135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2136. {
  2137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2138. }
  2139. }
  2140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2141. }
  2142. else
  2143. {
  2144. for (int index = 0; index < AC_QUANTITY; index++)
  2145. {
  2146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2147. {
  2148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2149. }
  2150. }
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2152. }// END FOR AC ELSE
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2156. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2159. //Power.Active.Export
  2160. //idx_sample=3;
  2161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2162. {
  2163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2164. {
  2165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2166. {
  2167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2168. }
  2169. }
  2170. for (int index = 0; index < CCS_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2173. {
  2174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2175. }
  2176. }
  2177. for (int index = 0; index < GB_QUANTITY; index++)
  2178. {
  2179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2180. {
  2181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2182. }
  2183. }
  2184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2185. }
  2186. else
  2187. {
  2188. for (int index = 0; index < AC_QUANTITY; index++)
  2189. {
  2190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2191. {
  2192. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2193. }
  2194. }
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2196. }// END FOR AC ELSE
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2200. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2203. //Voltage
  2204. //idx_sample=4;
  2205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2206. {
  2207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2208. {
  2209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2210. {
  2211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2212. }
  2213. }
  2214. for (int index = 0; index < CCS_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2217. {
  2218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2219. }
  2220. }
  2221. for (int index = 0; index < GB_QUANTITY; index++)
  2222. {
  2223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2224. {
  2225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2226. }
  2227. }
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2229. }
  2230. else
  2231. {
  2232. for (int index = 0; index < AC_QUANTITY; index++)
  2233. {
  2234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2235. {
  2236. 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
  2237. }
  2238. }
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2240. }// END FOR AC ELSE
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2244. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2247. //SoC
  2248. //idx_sample=5;
  2249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2250. {
  2251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2254. {
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2256. }
  2257. }
  2258. for (int index = 0; index < CCS_QUANTITY; index++)
  2259. {
  2260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2261. {
  2262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2263. }
  2264. }
  2265. for (int index = 0; index < GB_QUANTITY; index++)
  2266. {
  2267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2268. {
  2269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2270. }
  2271. }
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2278. } // END FOR DC CASE
  2279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2280. {
  2281. 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\"}]}]}]"
  2282. ,MESSAGE_TYPE_CALL
  2283. ,guid
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2286. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2289. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2292. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2298. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2332. );
  2333. }
  2334. else
  2335. {
  2336. 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\"}]}]}]"
  2337. ,MESSAGE_TYPE_CALL
  2338. ,guid
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2344. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2380. );
  2381. }
  2382. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2383. if(hashmap_operation(0, guid, tempdata) == 1)
  2384. {
  2385. result = PASS;
  2386. DEBUG_INFO("StopTransaction mapitem pass\n");
  2387. }
  2388. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2389. if(GetTransactionQueueNum() == 1)
  2390. {
  2391. LWS_Send(queuedata);
  2392. }
  2393. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2394. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2395. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2396. {
  2397. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2398. }
  2399. #if 0
  2400. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2401. if(hashmap_operation(0, guid, tempdata) == 1)
  2402. {
  2403. result = PASS;
  2404. DEBUG_INFO("StopTransaction mapitem pass\n");
  2405. }
  2406. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2407. #endif
  2408. //for test
  2409. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2410. return result;
  2411. }
  2412. int sendMeterValuesRequest(int gun_index)
  2413. {
  2414. mtrace();
  2415. int result = FAIL;
  2416. // char message[1500]={0};
  2417. char guid[37]={0};
  2418. //int idx_sample=0;
  2419. //int length = 0;
  2420. char tempdata[65]={0};
  2421. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2422. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2423. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2424. {
  2425. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2426. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2427. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2428. return result;
  2429. }
  2430. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2431. {
  2432. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2433. }
  2434. memset(queuedata, 0, sizeof(queuedata));
  2435. //set value
  2436. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2437. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2438. random_uuid(guid);
  2439. //UTC Date time
  2440. struct timeval tmnow;
  2441. struct tm *tm;
  2442. char buf[28];//, usec_buf[6];
  2443. gettimeofday(&tmnow, NULL);
  2444. time_t t;
  2445. t = time(NULL);
  2446. /*UTC time and date*/
  2447. tm = gmtime(&t);
  2448. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2450. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2451. //idx_sample=0;
  2452. //********************************(1)Current.Export************************************************/
  2453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2454. {
  2455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2458. {
  2459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2460. }
  2461. }
  2462. for (int index = 0; index < CCS_QUANTITY; index++)
  2463. {
  2464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2465. {
  2466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2467. }
  2468. }
  2469. for (int index = 0; index < GB_QUANTITY; index++)
  2470. {
  2471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2472. {
  2473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2474. }
  2475. }
  2476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2477. }
  2478. else
  2479. {
  2480. for (int index = 0; index < AC_QUANTITY; index++)
  2481. {
  2482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2483. {
  2484. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2485. }
  2486. }
  2487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2488. }// END FOR AC ELSE
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2492. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2495. //idx_sample=1;
  2496. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2498. {
  2499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2500. {
  2501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2502. {
  2503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2504. }
  2505. }
  2506. for (int index = 0; index < CCS_QUANTITY; index++)
  2507. {
  2508. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2510. {
  2511. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2513. }
  2514. }
  2515. for (int index = 0; index < GB_QUANTITY; index++)
  2516. {
  2517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2518. {
  2519. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2520. }
  2521. }
  2522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2523. }
  2524. else
  2525. {
  2526. for (int index = 0; index < AC_QUANTITY; index++)
  2527. {
  2528. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2529. {
  2530. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2531. }
  2532. }
  2533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2534. }//END FOR AC ELSE
  2535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2538. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2541. //idx_sample=2;
  2542. //********************************(4)Power.Active.Export************************************************/
  2543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2544. {
  2545. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2546. {
  2547. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2548. {
  2549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2550. }
  2551. }
  2552. for (int index = 0; index < CCS_QUANTITY; index++)
  2553. {
  2554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2555. {
  2556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2557. }
  2558. }
  2559. for (int index = 0; index < GB_QUANTITY; index++)
  2560. {
  2561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2562. {
  2563. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2568. }
  2569. else
  2570. {
  2571. for (int index = 0; index < AC_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2576. }
  2577. }
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2579. }// END FOR AC ELSE
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2583. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2586. //idx_sample=3;
  2587. //***********************************************(5)VOLTAGE******************************************************/
  2588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2589. {
  2590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2591. {
  2592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2593. {
  2594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2595. }
  2596. }
  2597. for (int index = 0; index < CCS_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2602. }
  2603. }
  2604. for (int index = 0; index < GB_QUANTITY; index++)
  2605. {
  2606. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2607. {
  2608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2609. }
  2610. }
  2611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2612. }
  2613. else
  2614. {
  2615. for (int index = 0; index < AC_QUANTITY; index++)
  2616. {
  2617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2618. {
  2619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2620. }
  2621. }
  2622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2623. }//END FOR AC ELSE
  2624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2627. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2631. {
  2632. //idx_sample=4;
  2633. //sampledValue = NULL;
  2634. //***********************************************(6)SOC******************************************************/
  2635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2636. {
  2637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2638. {
  2639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2640. }
  2641. }
  2642. for (int index = 0; index < CCS_QUANTITY; index++)
  2643. {
  2644. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2645. {
  2646. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2647. }
  2648. }
  2649. for (int index = 0; index < GB_QUANTITY; index++)
  2650. {
  2651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2652. {
  2653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2654. }
  2655. }
  2656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2662. }
  2663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2664. {
  2665. 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\"}]}]}]"
  2666. ,MESSAGE_TYPE_CALL
  2667. ,guid
  2668. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2669. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2670. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2706. );
  2707. }
  2708. else
  2709. {
  2710. 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\"}]}]}]"
  2711. ,MESSAGE_TYPE_CALL
  2712. ,guid
  2713. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2714. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2715. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2744. );
  2745. }
  2746. // Put request guid to hash map
  2747. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2748. 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*/)
  2749. {
  2750. result = PASS;
  2751. DEBUG_INFO("MeterValues mapitem pass\n");
  2752. }
  2753. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2754. if(GetTransactionQueueNum() == 1)
  2755. {
  2756. LWS_Send(queuedata);
  2757. }
  2758. #if 0
  2759. // Put request guid to hash map
  2760. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2761. 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*/)
  2762. {
  2763. result = PASS;
  2764. DEBUG_INFO("MeterValues mapitem pass\n");
  2765. }
  2766. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2767. #endif
  2768. return result;
  2769. }
  2770. //==========================================
  2771. // send confirm routine
  2772. //==========================================
  2773. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2774. {
  2775. mtrace();
  2776. int result = FAIL;
  2777. char message[100]={0};
  2778. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2779. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2780. LWS_Send(message);
  2781. result = TRUE;
  2782. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2783. return result;
  2784. }
  2785. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2786. {
  2787. mtrace();
  2788. int result = FAIL;
  2789. char message[100]={0};
  2790. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2791. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2792. LWS_Send(message);
  2793. result = TRUE;
  2794. return result;
  2795. }
  2796. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2797. {
  2798. mtrace();
  2799. int result = FAIL;
  2800. char message[100]={0};
  2801. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2802. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2803. LWS_Send(message);
  2804. result = TRUE;
  2805. return result;
  2806. }
  2807. int sendClearCacheConfirmation(char *uuid,char *payload)
  2808. {
  2809. mtrace();
  2810. int result = FAIL;
  2811. char message[500]={0};
  2812. // int count = 0;
  2813. // int gun_index = 0;
  2814. // char guid[37];
  2815. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2816. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2817. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2818. LWS_Send(message);
  2819. return result;
  2820. }
  2821. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2822. {
  2823. mtrace();
  2824. int result = FAIL;
  2825. char message[500]={0};
  2826. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2827. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2828. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2829. LWS_Send(message);
  2830. return result;
  2831. }
  2832. int sendDataTransferConfirmation(char *uuid,char *payload)
  2833. {
  2834. mtrace();
  2835. char statusStr[20]={0};
  2836. char dataStr[10]={0};
  2837. char sstr[20]={0};
  2838. int c = 0;
  2839. char *loc;
  2840. int result = FAIL;
  2841. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2842. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2843. /**********************status**************************/
  2844. loc = strstr(payload, "status");
  2845. memset(sstr ,0, sizeof(sstr) );
  2846. c = 0;
  2847. while (loc[3+strlen("status")+c] != '\"')
  2848. {
  2849. sstr[c] = loc[3+strlen("status")+c];
  2850. c++;
  2851. }
  2852. sstr[c] = '\0';
  2853. strcpy(statusStr, sstr);
  2854. /**********************data**************************/
  2855. loc = strstr(payload, "data");
  2856. memset(sstr ,0, sizeof(sstr) );
  2857. c = 0;
  2858. while (loc[3+strlen("data")+c] != '\"')
  2859. {
  2860. sstr[c] = loc[3+strlen("data")+c];
  2861. c++;
  2862. }
  2863. sstr[c] = '\0';
  2864. strcpy(dataStr, sstr);
  2865. return result;
  2866. }
  2867. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2868. {
  2869. mtrace();
  2870. int result = FAIL;
  2871. char message[1000]={0};
  2872. double diff_f = 0.0;
  2873. int diff_i = 0;
  2874. int diffSeconds = 0;
  2875. struct tm tp;
  2876. int TimeZero = FALSE;
  2877. int CompositeScheduleIndex = 0;
  2878. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2879. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2880. {
  2881. TimeZero = TRUE;
  2882. }
  2883. else
  2884. {
  2885. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2886. }
  2887. if(TimeZero == FALSE)
  2888. {
  2889. tp.tm_isdst = -1;
  2890. time_t utc = mktime(&tp);
  2891. time_t t = time(NULL);
  2892. diff_f = difftime(t, utc);
  2893. diff_i = (int)diff_f;
  2894. diffSeconds = diff_i % 86400;//86400 seconds/day
  2895. }
  2896. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2897. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2898. #if 0 //remove temporally
  2899. 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}"
  2900. ,MESSAGE_TYPE_CALLRESULT
  2901. ,uuid
  2902. ,payload
  2903. ,connectorIdInt
  2904. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2905. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2906. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2907. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2908. #endif
  2909. if(nPeriod == 0)
  2910. {
  2911. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2912. {
  2913. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2914. ,MESSAGE_TYPE_CALLRESULT
  2915. ,uuid
  2916. ,payload
  2917. ,connectorIdInt);
  2918. }
  2919. else
  2920. {
  2921. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2922. ,MESSAGE_TYPE_CALLRESULT
  2923. ,uuid
  2924. ,payload
  2925. ,connectorIdInt
  2926. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2927. }
  2928. }
  2929. else
  2930. {
  2931. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2932. ,MESSAGE_TYPE_CALLRESULT
  2933. ,uuid
  2934. ,payload
  2935. ,connectorIdInt
  2936. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2937. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2938. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2939. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2940. int len = nPeriod;
  2941. //Last Period StartPriod is less than diffSeconds
  2942. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2943. {
  2944. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2945. , 0
  2946. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2947. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2948. }
  2949. else
  2950. {
  2951. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2952. {
  2953. 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)
  2954. {
  2955. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2956. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2957. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2958. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2959. }
  2960. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2961. {
  2962. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2963. , ((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*/))
  2964. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2965. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2966. }
  2967. }
  2968. }
  2969. sprintf(message + strlen(message), "]}}]");
  2970. }
  2971. LWS_Send(message);
  2972. result = TRUE;
  2973. return result;
  2974. }
  2975. int sendGetConfigurationConfirmation(char *uuid)
  2976. {
  2977. mtrace();
  2978. int result = FAIL;
  2979. int MaxKeySupported = 0;
  2980. int sentConfigurationNumber= 0;
  2981. int sentunConfigurationNumber= 0;
  2982. char message[4000]={0};
  2983. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2984. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2985. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2986. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  2987. ,MESSAGE_TYPE_CALLRESULT
  2988. ,uuid );
  2989. //configuration key
  2990. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2991. {
  2992. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2993. {
  2994. if (sentConfigurationNumber == 0)
  2995. {
  2996. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2997. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2998. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2999. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3000. }
  3001. else
  3002. {
  3003. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3004. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3005. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3006. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3007. }
  3008. sentConfigurationNumber = sentConfigurationNumber + 1;
  3009. }
  3010. }
  3011. sprintf(message + strlen(message), "]");
  3012. if(UnknownKeynum != 0)
  3013. {
  3014. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3015. //unkown key
  3016. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3017. {
  3018. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3019. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3020. if(sentunConfigurationNumber == 0)
  3021. {
  3022. sprintf(message + strlen(message), "\"%s\""
  3023. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3024. }
  3025. else
  3026. {
  3027. sprintf(message + strlen(message), ",\"%s\""
  3028. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3029. }
  3030. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3031. }
  3032. sprintf(message + strlen(message), "]");
  3033. }
  3034. sprintf(message + strlen(message), "}]");
  3035. LWS_Send(message);
  3036. return result;
  3037. }
  3038. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3039. {
  3040. mtrace();
  3041. int result = FAIL;
  3042. char message[400]={0};
  3043. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3044. if(strcmp(payload,"")==0)
  3045. {
  3046. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3047. }
  3048. else
  3049. {
  3050. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3051. }
  3052. LWS_Send(message);
  3053. result = TRUE;
  3054. return result;
  3055. }
  3056. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3057. {
  3058. mtrace();
  3059. int result = FAIL;
  3060. char message[80]={0};
  3061. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3062. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3063. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3064. LWS_Send(message);
  3065. result = TRUE;
  3066. return result;
  3067. }
  3068. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3069. {
  3070. mtrace();
  3071. int result = FAIL;
  3072. char message[80]={0};
  3073. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3074. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3075. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3076. LWS_Send(message);
  3077. result = TRUE;
  3078. return result;
  3079. }
  3080. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3081. {
  3082. mtrace();
  3083. int result = FAIL;
  3084. char message[80]={0};
  3085. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3086. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3088. LWS_Send(message);
  3089. result = TRUE;
  3090. return result;
  3091. }
  3092. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3093. {
  3094. mtrace();
  3095. int result = FAIL;
  3096. char message[80]={0};
  3097. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3098. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3099. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendResetConfirmation(char *uuid,char *payload)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3109. char message[80]={0};
  3110. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3112. LWS_Send(message);
  3113. result = TRUE;
  3114. return result;
  3115. }
  3116. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3117. {
  3118. mtrace();
  3119. int result = FAIL;
  3120. char message[500]={0};
  3121. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3122. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3123. LWS_Send(message);
  3124. result = TRUE;
  3125. return result;
  3126. }
  3127. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3128. {
  3129. mtrace();
  3130. int result = FAIL;
  3131. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3132. char message[80]={0};
  3133. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3134. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3135. LWS_Send(message);
  3136. result = TRUE;
  3137. return result;
  3138. }
  3139. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3140. {
  3141. mtrace();
  3142. int result = FAIL;
  3143. char message[80]={0};
  3144. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3146. LWS_Send(message);
  3147. result = TRUE;
  3148. return result;
  3149. }
  3150. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3151. {
  3152. mtrace();
  3153. int result = FAIL;
  3154. char message[80]={0};
  3155. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3156. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3157. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3158. LWS_Send(message);
  3159. result = TRUE;
  3160. return result;
  3161. }
  3162. int sendUpdateFirmwareConfirmation(char *uuid)
  3163. {
  3164. mtrace();
  3165. int result = FAIL;
  3166. char message[60]={0};
  3167. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3168. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3169. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. //==========================================
  3175. // send CallError routine
  3176. //==========================================
  3177. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3178. {
  3179. mtrace();
  3180. //int result = FAIL;
  3181. char message[220]={0};
  3182. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3183. #ifdef SystemLogMessage
  3184. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3185. uniqueId, action, errorCode, errorDescription);
  3186. #endif
  3187. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3188. LWS_Send(message);
  3189. //result = TRUE;
  3190. }
  3191. //==========================================
  3192. // Handle server request routine Start
  3193. //==========================================
  3194. #define GUN_NUM 1
  3195. int handleCancelReservationRequest(char *uuid, char *payload)
  3196. {
  3197. mtrace();
  3198. int result = FAIL;
  3199. int gunNO = 0;
  3200. int reservationIdInt =0;
  3201. char comfirmstr[20];
  3202. int c = 0;
  3203. char *loc;
  3204. char sstr[100]={0};
  3205. DEBUG_INFO("handle CancelReservationRequest\n");
  3206. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3207. c = 0;
  3208. loc = strstr(payload, "reservationId");
  3209. memset(sstr ,0, sizeof(sstr) );
  3210. while (loc[strlen("reservationId")+2+c] != '}')
  3211. {
  3212. sstr[c] = loc[strlen("reservationId")+2+c];
  3213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3214. c++;
  3215. }
  3216. sstr[c] = '\0';
  3217. reservationIdInt = atoi(sstr);
  3218. memset(comfirmstr, 0, sizeof comfirmstr);
  3219. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3220. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3221. //check Transaction active
  3222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3223. {
  3224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3225. {
  3226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3227. {
  3228. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3229. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3230. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3231. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3232. goto end;
  3233. }
  3234. }
  3235. for (int index = 0; index < CCS_QUANTITY; index++)
  3236. {
  3237. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3238. {
  3239. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3240. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3241. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3242. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3243. goto end;
  3244. }
  3245. }
  3246. for (int index = 0; index < GB_QUANTITY; index++)
  3247. {
  3248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3249. {
  3250. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3251. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3252. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3253. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3254. goto end;
  3255. }
  3256. }
  3257. }
  3258. else
  3259. {
  3260. for (int index = 0; index < AC_QUANTITY; index++)
  3261. {
  3262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3263. {
  3264. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3265. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3266. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3267. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3268. goto end;
  3269. }
  3270. }
  3271. }// END FOR AC ELSE
  3272. //The reservationId does NOT match the reservationId
  3273. sendCancelReservationConfirmation(uuid, comfirmstr);
  3274. end:
  3275. // Fill in ocpp packet uuid
  3276. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3277. return result;
  3278. }
  3279. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3280. {
  3281. mtrace();
  3282. int result = FAIL;
  3283. int gunIndex = 0;
  3284. int copyTo = 0;
  3285. char sstr[90]={0};
  3286. char typeStr[16]={0};
  3287. char comfirmstr[20];
  3288. int specificId = FALSE;
  3289. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3290. char *loc;
  3291. //int intervalInt = 0;
  3292. int c = 0;
  3293. /*** connectorId ****/
  3294. loc = strstr(payload, "connectorId");
  3295. memset(sstr ,0, sizeof(sstr) );
  3296. c = 0;
  3297. copyTo = 0;
  3298. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3299. {
  3300. if(loc[strlen("connectorId")+2+c] != ' ')
  3301. {
  3302. sstr[copyTo] = loc[strlen("connectorId")+2+c];
  3303. copyTo = copyTo + 1;
  3304. }
  3305. c++;
  3306. }
  3307. sstr[copyTo] = '\0';
  3308. gunIndex = atoi(sstr);
  3309. /***type ****/
  3310. loc = strstr(payload, "type");
  3311. memset(sstr ,0, sizeof(sstr) );
  3312. c = 0;
  3313. copyTo = 0;
  3314. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3315. {
  3316. if(loc[3+strlen("type")+c] != ' ')
  3317. {
  3318. sstr[copyTo] = loc[3+strlen("type")+c];
  3319. copyTo = copyTo + 1;
  3320. }
  3321. c++;
  3322. }
  3323. sstr[copyTo] = '\0';
  3324. strcpy(typeStr, sstr);
  3325. if(gunIndex != 0)
  3326. {
  3327. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3328. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3329. }
  3330. else
  3331. {
  3332. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3333. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3334. }
  3335. memset(comfirmstr, 0, sizeof comfirmstr);
  3336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3337. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3338. {
  3339. specificId = TRUE;
  3340. }
  3341. if(specificId == FALSE)
  3342. goto end;
  3343. if(gunIndex != 0)
  3344. {
  3345. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3346. }
  3347. else
  3348. {
  3349. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3350. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3351. }
  3352. /*
  3353. enum SYSTEM_STATUS
  3354. {
  3355. SYS_MODE_BOOTING = 0,
  3356. SYS_MODE_IDLE = 1,
  3357. SYS_MODE_AUTHORIZING = 2,
  3358. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3359. SYS_MODE_REASSIGN = 4,
  3360. SYS_MODE_PREPARING = 5,
  3361. SYS_MODE_PREPARE_FOR_EV = 6,
  3362. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3363. SYS_MODE_CHARGING = 8,
  3364. SYS_MODE_TERMINATING = 9,
  3365. SYS_MODE_COMPLETE = 10,
  3366. SYS_MODE_ALARM = 11,
  3367. SYS_MODE_FAULT = 12,
  3368. SYS_MODE_RESERVATION = 13,
  3369. SYS_MODE_BOOKING = 14,
  3370. SYS_MODE_MAINTAIN = 15,
  3371. SYS_MODE_DEBUG = 16,
  3372. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3373. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3374. SYS_MODE_UPDATE = 19
  3375. };
  3376. */
  3377. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3378. {
  3379. //check Transaction active
  3380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3381. {
  3382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3383. {
  3384. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3385. {
  3386. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3387. {
  3388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3389. }
  3390. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3391. {
  3392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3393. }
  3394. else
  3395. {
  3396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3397. }
  3398. goto end;
  3399. }
  3400. }//END FOR CHAdeMO_QUANTITY
  3401. for (int index = 0; index < CCS_QUANTITY; index++)
  3402. {
  3403. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3404. {
  3405. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3406. {
  3407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3408. }
  3409. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3410. {
  3411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3412. }
  3413. else
  3414. {
  3415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3416. }
  3417. goto end;
  3418. }
  3419. }//END FOR CCS_QUANTITY
  3420. for (int index = 0; index < GB_QUANTITY; index++)
  3421. {
  3422. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3423. {
  3424. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3425. {
  3426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3427. }
  3428. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3429. {
  3430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3431. }
  3432. else
  3433. {
  3434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3435. }
  3436. goto end;
  3437. }
  3438. }// END FOR GB_QUANTITY
  3439. }
  3440. else
  3441. {
  3442. for (int index = 0; index < AC_QUANTITY; index++)
  3443. {
  3444. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3445. {
  3446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3447. {
  3448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3449. }
  3450. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3451. {
  3452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3453. }
  3454. else
  3455. {
  3456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3457. }
  3458. goto end;
  3459. }
  3460. }//END FOR AC_QUANTITY
  3461. }// END FOR AC ELSE
  3462. }//END FOR AvailabilityTypeStr[Inoperative]
  3463. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3464. {
  3465. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3466. //check Transaction active
  3467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3468. {
  3469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3470. {
  3471. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3474. goto end;
  3475. }
  3476. }//END FOR CHAdeMO_QUANTITY
  3477. for (int index = 0; index < CCS_QUANTITY; index++)
  3478. {
  3479. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3480. {
  3481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3482. goto end;
  3483. }
  3484. }//END FOR CCS_QUANTITY
  3485. for (int index = 0; index < GB_QUANTITY; index++)
  3486. {
  3487. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3488. {
  3489. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3491. goto end;
  3492. }
  3493. }// END FOR GB_QUANTITY
  3494. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3495. }
  3496. else
  3497. {
  3498. for (int index = 0; index < AC_QUANTITY; index++)
  3499. {
  3500. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3501. {
  3502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3503. goto end;
  3504. }
  3505. }//END FOR CHAdeMO_QUANTITY
  3506. }//END FOR AC ELSE
  3507. }//END FOR AvailabilityTypeStr[Operative]
  3508. end:
  3509. if(gunIndex != 0)
  3510. {
  3511. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3512. }
  3513. else
  3514. {
  3515. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3516. }
  3517. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3518. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3519. return result;
  3520. }
  3521. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3522. {
  3523. mtrace();
  3524. int result = FAIL;
  3525. char sstr[100]={0};
  3526. char keystr[40]={0};
  3527. char valuestr[100]={0};
  3528. char *loc;
  3529. int c = 0;
  3530. char comfirmstr[20]={0};
  3531. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3532. /***key ****/
  3533. loc = strstr(payload, "key");
  3534. memset(sstr ,0, sizeof(sstr) );
  3535. c = 0;
  3536. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3537. {
  3538. sstr[c] = loc[3+strlen("key")+c];
  3539. c++;
  3540. }
  3541. sstr[c] = '\0';
  3542. strcpy(keystr, sstr);
  3543. //DEBUG_INFO( "keystr=%s\n",keystr);
  3544. /***value ****/
  3545. loc = strstr(payload, "value");
  3546. memset(sstr ,0, sizeof(sstr) );
  3547. c = 0;
  3548. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3549. {
  3550. sstr[c] = loc[3+strlen("value")+c];
  3551. c++;
  3552. }
  3553. sstr[c] = '\0';
  3554. strcpy(valuestr, sstr);
  3555. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3556. if((uuid==NULL) || (payload ==NULL) )
  3557. {
  3558. #ifdef Debug
  3559. DEBUG_INFO("payload is null\n");
  3560. #endif
  3561. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3562. }
  3563. else
  3564. {
  3565. int status = setKeyValue(keystr, valuestr);
  3566. switch(status)
  3567. {
  3568. case ConfigurationStatus_Accepted:
  3569. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3570. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3571. StoreConfigurationTable();
  3572. break;
  3573. case ConfigurationStatus_Rejected:
  3574. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3575. break;
  3576. case RebootRequired:
  3577. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3578. StoreConfigurationTable();
  3579. break;
  3580. case NotSupported:
  3581. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3582. break;
  3583. default:
  3584. break;
  3585. }
  3586. }
  3587. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3588. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3589. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3590. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3591. {
  3592. ChageWebSocketPingInterval(atoi(valuestr));
  3593. }
  3594. return result;
  3595. }
  3596. int handleClearCacheRequest(char *uuid, char *payload)
  3597. {
  3598. mtrace();
  3599. int result = FAIL;
  3600. char comfirmstr[20];
  3601. int fd;
  3602. char rmFileCmd[100]={0};
  3603. struct stat stats;
  3604. DEBUG_INFO("handle ClearCacheRequest\n");
  3605. stat("/Storage/OCPP", &stats);
  3606. // Check for directory existence
  3607. if (S_ISDIR(stats.st_mode) == 1)
  3608. {
  3609. //DEBUG_ERROR("\n OCPP directory exist \n");
  3610. }
  3611. else
  3612. {
  3613. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3614. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3615. system(rmFileCmd);
  3616. }
  3617. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3618. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3619. {
  3620. DEBUG_INFO("AuthorizationCache file exist.\n");
  3621. }
  3622. else
  3623. {
  3624. DEBUG_INFO("AuthorizationCache file not exist\n");
  3625. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3626. if(log == NULL)
  3627. {
  3628. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3629. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3630. goto end;
  3631. }
  3632. else
  3633. {
  3634. fclose(log);
  3635. }
  3636. }
  3637. fd = open(AuthorizationCache_JSON,O_RDWR);
  3638. if(fd < 0)
  3639. {
  3640. DEBUG_INFO("open AuthorizationCache file failed\n");
  3641. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3642. }
  3643. else
  3644. {
  3645. DEBUG_INFO("open AuthorizationCache file successful\n");
  3646. //* 清空? 件 */
  3647. ftruncate(fd,0);
  3648. //* ? 新设置? 件? 移??*/
  3649. lseek(fd,0,SEEK_SET);
  3650. close(fd);
  3651. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3652. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3653. }
  3654. end:
  3655. sendClearCacheConfirmation(uuid, comfirmstr);
  3656. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3657. return result;
  3658. }
  3659. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3660. {
  3661. mtrace();
  3662. int result = FAIL;
  3663. int resultRename;
  3664. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3665. char chargingProfilePurposeStr[26]={0};
  3666. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3667. char tempchargingProfilePurposeStr[26]={0};
  3668. char sstr[160]={0};//sstr[200]={ 0 };
  3669. char str[100]={0};
  3670. int c = 0;
  3671. //int i = 0;
  3672. //char * pch;
  3673. char *loc;
  3674. char fname[200]={0};
  3675. char comfirmstr[20]={0};
  3676. char word[1600]={0};
  3677. int clearflag = FALSE;
  3678. int chargingProfileIdIsNULL = FALSE;
  3679. int connectorIsNULL = FALSE;
  3680. int chargingProfilePurposeIsNULL = FALSE;
  3681. int stackLevelIsNULL = FALSE;
  3682. //int GotoEnd = FALSE;
  3683. FILE *fptr1, *fptr2;
  3684. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3685. int n_chargingProfile=0;
  3686. int isEmptyFile = FALSE;
  3687. char sLineWord[1600]={0};
  3688. char chargingProfiles[10][100]={0};
  3689. int ChargeProfileCount = 0;
  3690. char ch;
  3691. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3692. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3693. //***id ****/
  3694. c = 0;
  3695. loc = strstr(payload, "id");
  3696. memset(sstr ,0, sizeof(sstr) );
  3697. if(loc == NULL)
  3698. {
  3699. chargingProfileIdIsNULL = TRUE;
  3700. }
  3701. else
  3702. {
  3703. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3704. {
  3705. sstr[c] = loc[strlen("id")+2+c];
  3706. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3707. c++;
  3708. }
  3709. sstr[c] = '\0';
  3710. chargingProfileIdInt = atoi(sstr);
  3711. }
  3712. //***connectorId ****/
  3713. c=0;
  3714. loc = strstr(payload, "connectorId");
  3715. memset(sstr ,0, sizeof(sstr) );
  3716. if(loc == NULL)
  3717. {
  3718. connectorIsNULL = TRUE;
  3719. }
  3720. else
  3721. {
  3722. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3723. {
  3724. sstr[c] = loc[strlen("connectorId")+2+c];
  3725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3726. c++;
  3727. }
  3728. sstr[c] = '\0';
  3729. connectorIdInt = atoi(sstr);
  3730. }
  3731. //***chargingProfilePurpose ****/
  3732. loc = strstr(payload, "chargingProfilePurpose");
  3733. memset(sstr ,0, sizeof(sstr) );
  3734. c = 0;
  3735. if(loc == NULL)
  3736. {
  3737. chargingProfilePurposeIsNULL = TRUE;
  3738. }
  3739. else
  3740. {
  3741. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3742. {
  3743. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3744. c++;
  3745. }
  3746. sstr[c] = '\0';
  3747. strcpy(chargingProfilePurposeStr, sstr);
  3748. }
  3749. //***stackLevel ****/
  3750. c=0;
  3751. loc = strstr(payload, "stackLevel");
  3752. memset(sstr ,0, sizeof(sstr) );
  3753. if(loc == NULL)
  3754. {
  3755. stackLevelIsNULL = TRUE;
  3756. }
  3757. else
  3758. {
  3759. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3760. {
  3761. sstr[c] = loc[strlen("stackLevel")+2+c];
  3762. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3763. c++;
  3764. }
  3765. sstr[c] = '\0';
  3766. stackLevelInt = atoi(sstr);
  3767. }
  3768. if(connectorIsNULL == FALSE)
  3769. {
  3770. switch(connectorIdInt)
  3771. {
  3772. case 0:
  3773. if(chargingProfilePurposeIsNULL == TRUE)
  3774. {
  3775. int l = 0;
  3776. strcpy(fname, ChargePointMaxProfile_JSON);
  3777. if((access(fname,F_OK))!=-1)
  3778. {
  3779. strcpy(chargingProfiles[l], fname);
  3780. l = l + 1;
  3781. }
  3782. strcpy(fname, TxDefaultProfile_0_JSON);
  3783. if((access(fname,F_OK))!=-1)
  3784. {
  3785. strcpy(chargingProfiles[l], fname);
  3786. l = l + 1;
  3787. }
  3788. ChargeProfileCount = l;
  3789. }
  3790. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3791. {
  3792. strcpy(fname, ChargePointMaxProfile_JSON);
  3793. if((access(fname,F_OK))!=-1)
  3794. {
  3795. strcpy(chargingProfiles[0], fname);
  3796. ChargeProfileCount = 1;
  3797. }
  3798. }
  3799. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3800. {
  3801. strcpy(fname, TxDefaultProfile_0_JSON);
  3802. if((access(fname,F_OK))!=-1)
  3803. {
  3804. strcpy(chargingProfiles[0], fname);
  3805. ChargeProfileCount = 1;
  3806. }
  3807. }
  3808. break;
  3809. default:
  3810. if(chargingProfilePurposeIsNULL == TRUE)
  3811. {
  3812. int m = 0;
  3813. memset(fname, 0, sizeof fname);
  3814. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3815. if((access(fname,F_OK))!=-1)
  3816. {
  3817. strcpy(chargingProfiles[m], fname);
  3818. m = m + 1;
  3819. }
  3820. memset(fname, 0, sizeof fname);
  3821. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3822. if((access(fname,F_OK))!=-1)
  3823. {
  3824. strcpy(chargingProfiles[m], fname);
  3825. m = m + 1;
  3826. }
  3827. ChargeProfileCount = m;
  3828. }
  3829. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3830. {
  3831. //strcpy(fname, TxDefaultProfile_1_JSON);
  3832. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3833. if((access(fname,F_OK))!=-1)
  3834. {
  3835. strcpy(chargingProfiles[0], fname);
  3836. ChargeProfileCount = 1;
  3837. }
  3838. }
  3839. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3840. {
  3841. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3842. if((access(fname,F_OK))!=-1)
  3843. {
  3844. strcpy(chargingProfiles[0], fname);
  3845. ChargeProfileCount = 1;
  3846. }
  3847. //strcpy(fname, TxProfile_1_JSON);
  3848. }
  3849. //strcpy(fname, ChargePointMaxProfile_JSON );
  3850. break;
  3851. }
  3852. }
  3853. else // Check all Charging Profiles
  3854. {
  3855. int i = 0;
  3856. char fnametemp[200]={0};
  3857. ChargeProfileCount = 0;
  3858. //Check ChargePointMaxProfile.json exit
  3859. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3860. {
  3861. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3862. i = i + 1;
  3863. }
  3864. //Check TxDefaultProfile_0.json exit
  3865. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3866. {
  3867. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3868. i = i + 1;
  3869. }
  3870. //Check TxDefaultProfile_%d.json
  3871. for(int j=1; j <= gunTotalNumber; j++)
  3872. {
  3873. memset(fnametemp, 0, sizeof fnametemp);
  3874. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3875. if((access(fnametemp,F_OK))!=-1)
  3876. {
  3877. strcpy(chargingProfiles[i], fnametemp);
  3878. i = i + 1;
  3879. }
  3880. }
  3881. //Check TxProfile_%d.json
  3882. for(int j=1; j <= gunTotalNumber; j++)
  3883. {
  3884. memset(fnametemp, 0, sizeof fnametemp);
  3885. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3886. if((access(fnametemp,F_OK))!=-1)
  3887. {
  3888. strcpy(chargingProfiles[i], fnametemp);
  3889. i = i + 1;
  3890. }
  3891. }
  3892. ChargeProfileCount = i;
  3893. }// End connectorIsNULL is TRUE
  3894. if(ChargeProfileCount == 0)
  3895. {
  3896. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3897. goto end;
  3898. }
  3899. #if 0
  3900. fptr1 = fopen(fname, "r");
  3901. if (!fptr1)
  3902. {
  3903. //file not exist
  3904. DEBUG_INFO("Unable to open the input file!!\n");
  3905. fptr1 = fopen(fname, "w+");
  3906. }
  3907. fclose(fptr1);
  3908. #endif
  3909. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3910. {
  3911. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3912. goto end;
  3913. }
  3914. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3915. {
  3916. memset(str, 0, sizeof str);
  3917. // clear temp file
  3918. sprintf(str,"rm -f %s",temp);
  3919. system(str);
  3920. for(int k=0; k < ChargeProfileCount; k++)
  3921. {
  3922. memset(str, 0, sizeof str);
  3923. //clear file in C
  3924. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3925. system(str);
  3926. }
  3927. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3928. goto end;
  3929. }
  3930. else if(connectorIsNULL == TRUE)
  3931. {
  3932. for(int k=0; k < ChargeProfileCount; k++)
  3933. {
  3934. fptr1 = fopen(chargingProfiles[k], "r");
  3935. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3936. //Check Charging Profile Count
  3937. while(fscanf(fptr1, "%s", word) != EOF)
  3938. {
  3939. //DEBUG_INFO("word=%s\n",word);
  3940. if(strstr(word, "chargingProfileId")!= NULL)
  3941. {
  3942. //DEBUG_INFO("test chargingProfileId \n");
  3943. n_chargingProfile = n_chargingProfile + 1;
  3944. //DEBUG_INFO("chargingProfileId Found\n");
  3945. }
  3946. }
  3947. rewind(fptr1);
  3948. //search Charging Profile Element
  3949. //int i= 0;
  3950. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3951. {
  3952. //------------------------tempconnectorIdInt------------------------//
  3953. loc = strstr(sLineWord, "connectorId");
  3954. c = 0;
  3955. memset(sstr ,0, sizeof(sstr) );
  3956. while (loc[strlen("connectorId")+2+c] != ',')
  3957. {
  3958. sstr[c] = loc[strlen("connectorId")+2+c];
  3959. c++;
  3960. }
  3961. sstr[c] = '\0';
  3962. tempconnectorIdInt = atoi(sstr);
  3963. printf("file's gun number is %d\n", tempconnectorIdInt);
  3964. //--------------------------chargingProfileId--------------------//
  3965. c = 0;
  3966. loc = strstr(sLineWord, "chargingProfileId");
  3967. memset(sstr ,0, sizeof(sstr) );
  3968. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3969. {
  3970. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3971. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3972. c++;
  3973. }
  3974. sstr[c] = '\0';
  3975. tempchargingProfileIdInt = atoi(sstr);
  3976. //stackLevel
  3977. c = 0;
  3978. loc = strstr(sLineWord, "stackLevel");
  3979. memset(sstr ,0, sizeof(sstr) );
  3980. while (loc[strlen("stackLevel")+2+c] != ',')
  3981. {
  3982. sstr[c] = loc[strlen("stackLevel")+2+c];
  3983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3984. c++;
  3985. }
  3986. sstr[c] = '\0';
  3987. tempstackLevelInt = atoi(sstr);
  3988. c = 0;
  3989. loc = strstr(sLineWord, "chargingProfilePurpose");
  3990. memset(sstr ,0, sizeof(sstr) );
  3991. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3992. {
  3993. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3994. c++;
  3995. }
  3996. sstr[c] = '\0';
  3997. strcpy(tempchargingProfilePurposeStr, sstr);
  3998. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  3999. {
  4000. //------- not write to fptr2-------//
  4001. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4002. //clearflag = TRUE;
  4003. }
  4004. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4005. {
  4006. //------- not write to fptr2-------//
  4007. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4008. }
  4009. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4010. {
  4011. //------- not write to fptr2-------//
  4012. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4013. }
  4014. else
  4015. {
  4016. fprintf(fptr2, sLineWord);//writing data into file
  4017. }
  4018. memset(sLineWord, 0, sizeof sLineWord);
  4019. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4020. if(clearflag == TRUE)
  4021. {
  4022. fclose(fptr1);
  4023. fclose(fptr2);
  4024. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4025. system(str);
  4026. // clear temp file
  4027. sprintf(str,"rm -f %s",temp);
  4028. system(str);
  4029. }
  4030. else
  4031. {
  4032. fclose(fptr1);
  4033. fclose(fptr2);
  4034. memset(str, 0, sizeof str);
  4035. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4036. system(str);
  4037. resultRename = rename(temp, chargingProfiles[k]);
  4038. if(resultRename == 0)
  4039. {
  4040. DEBUG_INFO("File ChargingProfile renamed successfully");
  4041. }
  4042. else
  4043. {
  4044. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4045. }
  4046. if(comfirmstr[0]== 0)
  4047. {
  4048. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4049. }
  4050. //Check chargingProfile is empty file
  4051. /*------ Read the file ----------------*/
  4052. fptr1=fopen(chargingProfiles[k],"r");
  4053. ch=fgetc(fptr1);
  4054. rewind(fptr1);
  4055. memset(sLineWord, 0, sizeof sLineWord);
  4056. if(ch!=EOF)
  4057. {
  4058. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4059. {
  4060. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4061. if(sLineWord[0]=='\0')
  4062. {
  4063. isEmptyFile = TRUE;
  4064. break;
  4065. }
  4066. else
  4067. {
  4068. isEmptyFile = FALSE;
  4069. break;
  4070. }
  4071. }
  4072. }
  4073. fclose(fptr1);
  4074. if(isEmptyFile == TRUE)
  4075. {
  4076. memset(str, 0, sizeof str);
  4077. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4078. system(str);
  4079. }
  4080. }
  4081. }// End of while(int k=0; k < ChargePointCount; k++)
  4082. }
  4083. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4084. {
  4085. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4086. for(int k=0; k < ChargeProfileCount; k++)
  4087. {
  4088. fptr1 = fopen(chargingProfiles[k], "r");
  4089. fptr2 = fopen(temp, "w+");
  4090. //Check Charging Profile Count
  4091. while(fscanf(fptr1, "%s", word) != EOF)
  4092. {
  4093. //DEBUG_INFO("word=%s\n",word);
  4094. if(strstr(word, "chargingProfileId")!= NULL)
  4095. {
  4096. //DEBUG_INFO("test chargingProfileId \n");
  4097. n_chargingProfile = n_chargingProfile + 1;
  4098. //DEBUG_INFO("chargingProfileId Found\n");
  4099. }
  4100. }
  4101. rewind(fptr1);
  4102. //search Charging Profile Element
  4103. //int i= 0;
  4104. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4105. {
  4106. //*************************tempconnectorIdInt*********************************/
  4107. loc = strstr(sLineWord, "connectorId");
  4108. c = 0;
  4109. memset(sstr ,0, sizeof(sstr) );
  4110. while (loc[strlen("connectorId")+2+c] != ',')
  4111. {
  4112. sstr[c] = loc[strlen("connectorId")+2+c];
  4113. c++;
  4114. }
  4115. sstr[c] = '\0';
  4116. tempconnectorIdInt = atoi(sstr);
  4117. //chargingProfileId
  4118. c = 0;
  4119. loc = strstr(sLineWord, "chargingProfileId");
  4120. memset(sstr ,0, sizeof(sstr) );
  4121. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4122. {
  4123. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4124. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4125. c++;
  4126. }
  4127. sstr[c] = '\0';
  4128. tempchargingProfileIdInt = atoi(sstr);
  4129. //stackLevel
  4130. c = 0;
  4131. loc = strstr(sLineWord, "stackLevel");
  4132. memset(sstr ,0, sizeof(sstr) );
  4133. while (loc[strlen("stackLevel")+2+c] != ',')
  4134. {
  4135. sstr[c] = loc[strlen("stackLevel")+2+c];
  4136. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4137. c++;
  4138. }
  4139. sstr[c] = '\0';
  4140. tempstackLevelInt = atoi(sstr);
  4141. c = 0;
  4142. loc = strstr(sLineWord, "chargingProfilePurpose");
  4143. memset(sstr ,0, sizeof(sstr) );
  4144. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4145. {
  4146. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4147. c++;
  4148. }
  4149. sstr[c] = '\0';
  4150. strcpy(tempchargingProfilePurposeStr, sstr);
  4151. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4152. {
  4153. //------- not write to fptr2-------//
  4154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4155. //clearflag = TRUE;
  4156. }
  4157. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4158. {
  4159. //------- not write to fptr2-------//
  4160. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4161. }
  4162. else if(stackLevelIsNULL == TRUE)
  4163. {
  4164. //Clear Whole File
  4165. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4166. clearflag = TRUE;
  4167. break;
  4168. }
  4169. else
  4170. {
  4171. fprintf(fptr2, sLineWord);//writing data into file
  4172. }
  4173. memset(sLineWord, 0, sizeof sLineWord);
  4174. }
  4175. if(clearflag == TRUE)
  4176. {
  4177. fclose(fptr1);
  4178. fclose(fptr2);
  4179. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4180. system(str);
  4181. // clear temp file
  4182. sprintf(str,"rm -f %s",temp);
  4183. system(str);
  4184. }
  4185. else
  4186. {
  4187. fclose(fptr1);
  4188. fclose(fptr2);
  4189. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4190. system(str);
  4191. resultRename = rename(temp, chargingProfiles[k]);
  4192. if(resultRename == 0)
  4193. {
  4194. DEBUG_INFO("File ChargingProfile renamed successfully");
  4195. }
  4196. else
  4197. {
  4198. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4199. }
  4200. if(comfirmstr[0]== 0)
  4201. {
  4202. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4203. }
  4204. //Check chargingProfile is empty file
  4205. /*------ Read the file ----------------*/
  4206. fptr1=fopen(chargingProfiles[k],"r");
  4207. ch=fgetc(fptr1);
  4208. rewind(fptr1);
  4209. memset(sLineWord, 0, sizeof sLineWord);
  4210. if(ch!=EOF)
  4211. {
  4212. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4213. {
  4214. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4215. if(sLineWord[0]=='\0')
  4216. {
  4217. isEmptyFile = TRUE;
  4218. break;
  4219. }
  4220. else
  4221. {
  4222. isEmptyFile = FALSE;
  4223. break;
  4224. }
  4225. }
  4226. }
  4227. fclose(fptr1);
  4228. if(isEmptyFile == TRUE)
  4229. {
  4230. memset(str, 0, sizeof str);
  4231. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4232. system(str);
  4233. }
  4234. /*------- End of reading ---------------*/
  4235. }
  4236. } // while(int k=0; k < ChargeProfileCount; k++)
  4237. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4238. end:
  4239. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4240. return result;
  4241. }
  4242. int handleDataTransferRequest(char *uuid, char *payload)
  4243. {
  4244. mtrace();
  4245. int result = FAIL;
  4246. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4247. char tempvendorId[255]={0};
  4248. char tempmessageId[50]={0};
  4249. char tempdata[50]={0};
  4250. char sstr[160]={0};//sstr[200]={ 0 };
  4251. char message[80]={0};
  4252. int c = 0;
  4253. char *loc;
  4254. DEBUG_INFO("handle DataTransferRequest\n");
  4255. if((uuid != NULL) && (payload != NULL))
  4256. {
  4257. //===============================
  4258. // vendorId
  4259. //===============================
  4260. c = 0;
  4261. loc = strstr(payload, "vendorId");
  4262. while (loc[strlen("vendorId")+3+c] != '\"')
  4263. {
  4264. sstr[c] = loc[strlen("vendorId")+3+c];
  4265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4266. c++;
  4267. }
  4268. sstr[c] = '\0';
  4269. strcpy(tempvendorId,sstr);
  4270. //===============================
  4271. // messageId
  4272. //===============================
  4273. memset(sstr ,0, sizeof(sstr) );
  4274. c = 0;
  4275. loc = strstr(payload, "messageId");
  4276. while (loc[strlen("messageId")+3+c] != '\"')
  4277. {
  4278. sstr[c] = loc[strlen("messageId")+3+c];
  4279. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4280. c++;
  4281. }
  4282. sstr[c] = '\0';
  4283. strcpy(tempmessageId,sstr);
  4284. //===============================
  4285. // data
  4286. //===============================
  4287. memset(sstr ,0, sizeof(sstr) );
  4288. c = 0;
  4289. loc = strstr(payload, "data");
  4290. printf("loc=%s\n",loc);
  4291. while (loc[strlen("data")+3+c] != '\"')
  4292. {
  4293. sstr[c] = loc[strlen("data")+3+c];
  4294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4295. c++;
  4296. }
  4297. sstr[c] = '\0';
  4298. strcpy(tempdata,sstr);
  4299. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4300. }
  4301. else
  4302. {
  4303. char guid[37]={0};
  4304. random_uuid(guid);
  4305. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4306. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4307. }
  4308. LWS_Send(message);
  4309. return result;
  4310. }
  4311. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4312. {
  4313. mtrace();
  4314. int result = FAIL;
  4315. int connectorIdInt, durationInt;
  4316. char chargingRateUnitStr[4]={0};
  4317. //int tempconnectorIdInt,
  4318. int tempdurationInt;
  4319. float tempminChargingRateFloat = 0.0;
  4320. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4321. int tempStartPeriodInt=0;
  4322. float tempLimitInt=0.0;//0.1;
  4323. int tempNumberPhasesInt=0;
  4324. char fname[200];
  4325. char comfirmstr[20];
  4326. //float totallimit =0.0;
  4327. float MinChargingRate =0.0;
  4328. //double diff_t;
  4329. //struct tm tp;
  4330. FILE *fptr1;
  4331. int c = 0;
  4332. //int i = 0;
  4333. char * pch;
  4334. char *loc;
  4335. char sstr[200]={ 0 };
  4336. int n_chargingProfile = 0;
  4337. int n_SchedulePeriods = 0;
  4338. char SchedulePeriodList[10][200]={0};
  4339. char sLineWord[1600]={0};
  4340. //int n_periods = 0;
  4341. char word[1000]={0};
  4342. int confirmPeriods = 0;
  4343. struct StructProfile ChargePointMaxProfile;
  4344. struct StructProfile TxDefaultProfile;
  4345. struct StructProfile TxProfile;
  4346. struct StructProfile TxDefaultProfiletemp[2]={0};
  4347. int TxDefaultProfileFileIsNull=FALSE;
  4348. int ChargePointMaxProfileIsNull=FALSE;
  4349. int TxProfileIsNull=FALSE;
  4350. int CompositeSceduleIndex = 0;
  4351. char ChargePointMaxProfileScheduleStr[30]={0};
  4352. char TxDefaultProfileScheduleStr[30]={0};
  4353. char TxProfileScheduleStr[30]={0};
  4354. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4355. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4356. memset(&TxProfile,0,sizeof(struct StructProfile));
  4357. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4358. c=0;
  4359. loc = strstr(payload, "connectorId");
  4360. memset(sstr ,0, sizeof(sstr) );
  4361. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4362. {
  4363. sstr[c] = loc[strlen("connectorId")+2+c];
  4364. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4365. c++;
  4366. }
  4367. sstr[c] = '\0';
  4368. connectorIdInt = atoi(sstr);
  4369. c=0;
  4370. loc = strstr(payload, "duration");
  4371. memset(sstr ,0, sizeof(sstr) );
  4372. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4373. {
  4374. sstr[c] = loc[strlen("duration")+2+c];
  4375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4376. c++;
  4377. }
  4378. sstr[c] = '\0';
  4379. durationInt = atoi(sstr);
  4380. c = 0;
  4381. loc = strstr(payload, "chargingRateUnit");
  4382. memset(sstr ,0, sizeof(sstr) );
  4383. if(loc == NULL)
  4384. {
  4385. }
  4386. else
  4387. {
  4388. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4389. {
  4390. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4391. c++;
  4392. }
  4393. sstr[c] = '\0';
  4394. strcpy(chargingRateUnitStr, sstr);
  4395. }
  4396. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4397. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4398. if(connectorIdInt==0) // connectorId is 0
  4399. {
  4400. //******************************ChargePointMaxProfile*****************************************************/
  4401. strcpy(fname, ChargePointMaxProfile_JSON );
  4402. char word[30]={0};
  4403. char sLineWord[1060]={0};
  4404. int n_chargingProfile=0;
  4405. ChargePointMaxProfileIsNull=TRUE;
  4406. if((access(fname,F_OK))!=-1)
  4407. {
  4408. fptr1 = fopen(fname, "r");
  4409. int c;
  4410. c = fgetc(fptr1);
  4411. //DEBUG_INFO("c:%d\n",c);
  4412. rewind(fptr1);
  4413. if(c == EOF)
  4414. {
  4415. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4416. ChargePointMaxProfileIsNull=TRUE;
  4417. fclose(fptr1);
  4418. }
  4419. else
  4420. {
  4421. ChargePointMaxProfileIsNull=FALSE;
  4422. while(fscanf(fptr1, "%s", word) != EOF)
  4423. {
  4424. if(strcmp(word, "chargingProfileId") == 0)
  4425. {
  4426. n_chargingProfile = n_chargingProfile + 1;
  4427. printf("Found\n");
  4428. }
  4429. }
  4430. rewind(fptr1);
  4431. //search Charging Profile Element
  4432. int i= 0;
  4433. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4434. #if 0
  4435. /***********connectorId****************/
  4436. c = 0;
  4437. loc = strstr(sLineWord, "connectorId");
  4438. // printf("loc=%s\n",loc);
  4439. memset(sstr ,0, sizeof(sstr) );
  4440. while (loc[strlen("connectorId")+2+c] != ',')
  4441. {
  4442. sstr[c] = loc[strlen("connectorId")+2+c];
  4443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4444. c++;
  4445. }
  4446. sstr[c] = '\0';
  4447. tempconnectorIdInt = atoi(sstr);
  4448. #endif
  4449. //***********validFrom**************/
  4450. c = 0;
  4451. loc = strstr(sLineWord, "validFrom");
  4452. //DEBUG_INFO("loc=%s\n",loc);
  4453. memset(sstr ,0, sizeof(sstr) );
  4454. if(loc != NULL)
  4455. {
  4456. while (loc[3+strlen("validFrom")+c] != '\"')
  4457. {
  4458. sstr[c] = loc[3+strlen("validFrom")+c];
  4459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4460. c++;
  4461. }
  4462. sstr[c] = '\0';
  4463. DEBUG_INFO("validFrom=%s\n",sstr);
  4464. strcpy(tempvalidFromStr,sstr);
  4465. }
  4466. else
  4467. {
  4468. strcpy(tempvalidFromStr,"");
  4469. }
  4470. //**********startSchedule**********/
  4471. c = 0;
  4472. loc = strstr(sLineWord, "startSchedule");
  4473. //DEBUG_INFO("loc=%s\n",loc);
  4474. memset(sstr ,0, sizeof(sstr) );
  4475. while (loc[3+strlen("startSchedule")+c] != '\"')
  4476. {
  4477. sstr[c] = loc[3+strlen("startSchedule")+c];
  4478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4479. c++;
  4480. }
  4481. sstr[c] = '\0';
  4482. strcpy(tempstartScheduleStr, sstr);
  4483. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4484. //**********chargingRateUnit**********/
  4485. c = 0;
  4486. loc = strstr(sLineWord, "chargingRateUnit");
  4487. memset(sstr ,0, sizeof(sstr) );
  4488. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4489. {
  4490. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4491. c++;
  4492. }
  4493. sstr[c] = '\0';
  4494. strcpy(tempchargingRateUnitStr, sstr);
  4495. //**********minChargingRate*******/
  4496. c = 0;
  4497. loc = strstr(sLineWord, "minChargingRate");
  4498. //printf("loc=%s\n",loc);
  4499. if(loc != NULL)
  4500. {
  4501. memset(sstr ,0, sizeof(sstr) );
  4502. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4503. {
  4504. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4506. c++;
  4507. }
  4508. sstr[c] = '\0';
  4509. tempminChargingRateFloat = atof(sstr);
  4510. }
  4511. else
  4512. {
  4513. tempminChargingRateFloat = 0.0;
  4514. }
  4515. //
  4516. #if 0
  4517. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4518. tp.tm_isdst = -1;
  4519. time_t utc = mktime(&tp);
  4520. // current time
  4521. time_t t = time(NULL);
  4522. #endif
  4523. //diff_t = difftime(t, utc);
  4524. //parsing strings to words
  4525. i = 0;
  4526. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4527. loc = loc+3+strlen("chargingSchedulePeriod");
  4528. pch = strtok(loc ,"{");
  4529. while (pch != NULL)
  4530. {
  4531. strcpy(SchedulePeriodList[i], pch);
  4532. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4533. //printf ("%s\n",pch);
  4534. pch = strtok (NULL, "{");
  4535. i = i + 1;
  4536. }
  4537. n_SchedulePeriods = i;
  4538. for(int i=0;i<n_SchedulePeriods;i++)
  4539. {
  4540. //*************startPeriod****************/
  4541. c = 0;
  4542. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4543. memset(sstr ,0, sizeof(sstr) );
  4544. while (loc[strlen("startPeriod")+2+c] != ',')
  4545. {
  4546. sstr[c] = loc[strlen("startPeriod")+2+c];
  4547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4548. c++;
  4549. }
  4550. sstr[c] = '\0';
  4551. tempStartPeriodInt = atoi(sstr);
  4552. //*************limit****************/
  4553. c = 0;
  4554. loc = strstr(SchedulePeriodList[i], "limit");
  4555. memset(sstr ,0, sizeof(sstr) );
  4556. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4557. {
  4558. sstr[c] = loc[strlen("limit")+2+c];
  4559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4560. c++;
  4561. }
  4562. sstr[c] = '\0';
  4563. tempLimitInt = atof(sstr);
  4564. //*************numberPhases****************/
  4565. c = 0;
  4566. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4567. memset(sstr ,0, sizeof(sstr) );
  4568. if(loc != NULL)
  4569. {
  4570. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4571. {
  4572. sstr[c] = loc[strlen("numberPhases")+2+c];
  4573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4574. c++;
  4575. }
  4576. sstr[c] = '\0';
  4577. tempNumberPhasesInt = atoi(sstr);
  4578. }
  4579. else
  4580. {
  4581. tempNumberPhasesInt = 0;
  4582. }
  4583. ChargePointMaxProfile.Duration = durationInt;
  4584. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4585. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4586. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4587. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4588. }
  4589. if(MinChargingRate < tempminChargingRateFloat)
  4590. MinChargingRate = tempminChargingRateFloat;
  4591. }
  4592. }// End of file ChargingProfile
  4593. } //THE END OF ACCESS ChargePointMaxProfile
  4594. //******************************TxDefaultProfile***********************************************/
  4595. strcpy(fname, TxDefaultProfile_0_JSON);
  4596. memset(word, 0, 30);
  4597. memset(sLineWord, 0, 1060);
  4598. //char word[30]={0};
  4599. //char sLineWord[1060]={0};
  4600. n_chargingProfile=0;
  4601. TxDefaultProfileFileIsNull=TRUE;
  4602. if((access(fname,F_OK))!=-1)
  4603. {
  4604. fptr1 = fopen(fname, "r");
  4605. c = 0;
  4606. c = fgetc(fptr1);
  4607. //DEBUG_INFO("c:%d\n",c);
  4608. rewind(fptr1);
  4609. if(c == EOF)
  4610. {
  4611. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4612. TxDefaultProfileFileIsNull=TRUE;
  4613. fclose(fptr1);
  4614. }
  4615. else
  4616. {
  4617. TxDefaultProfileFileIsNull=FALSE;
  4618. while(fscanf(fptr1, "%s", word) != EOF)
  4619. {
  4620. if(strcmp(word, "chargingProfileId") == 0)
  4621. {
  4622. n_chargingProfile = n_chargingProfile + 1;
  4623. printf("Found\n");
  4624. }
  4625. }
  4626. rewind(fptr1);
  4627. //search Charging Profile Element
  4628. int i= 0;
  4629. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4630. #if 0
  4631. /***********connectorId****************/
  4632. c = 0;
  4633. loc = strstr(sLineWord, "connectorId");
  4634. // printf("loc=%s\n",loc);
  4635. memset(sstr ,0, sizeof(sstr) );
  4636. while (loc[strlen("connectorId")+2+c] != ',')
  4637. {
  4638. sstr[c] = loc[strlen("connectorId")+2+c];
  4639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4640. c++;
  4641. }
  4642. sstr[c] = '\0';
  4643. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4644. tempconnectorIdInt = atoi(sstr);
  4645. #endif
  4646. //***********validFrom**************/
  4647. c = 0;
  4648. loc = strstr(sLineWord, "validFrom");
  4649. //DEBUG_INFO("loc=%s\n",loc);
  4650. memset(sstr ,0, sizeof(sstr) );
  4651. if(loc != NULL)
  4652. {
  4653. while (loc[3+strlen("validFrom")+c] != '\"')
  4654. {
  4655. sstr[c] = loc[3+strlen("validFrom")+c];
  4656. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4657. c++;
  4658. }
  4659. sstr[c] = '\0';
  4660. DEBUG_INFO("validFrom=%s\n",sstr);
  4661. strcpy(tempvalidFromStr,sstr);
  4662. }
  4663. else
  4664. {
  4665. strcpy(tempvalidFromStr,"");
  4666. }
  4667. //**********startSchedule**********/
  4668. c = 0;
  4669. loc = strstr(sLineWord, "startSchedule");
  4670. //DEBUG_INFO("loc=%s\n",loc);
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[3+strlen("startSchedule")+c] != '\"')
  4673. {
  4674. sstr[c] = loc[3+strlen("startSchedule")+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. strcpy(tempstartScheduleStr, sstr);
  4680. strcpy(TxDefaultProfileScheduleStr, sstr);
  4681. //**********chargingRateUnit**********/
  4682. c = 0;
  4683. loc = strstr(sLineWord, "chargingRateUnit");
  4684. memset(sstr ,0, sizeof(sstr) );
  4685. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4686. {
  4687. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4688. c++;
  4689. }
  4690. sstr[c] = '\0';
  4691. strcpy(tempchargingRateUnitStr, sstr);
  4692. //**********minChargingRate*******/
  4693. c = 0;
  4694. loc = strstr(sLineWord, "minChargingRate");
  4695. //printf("loc=%s\n",loc);
  4696. if(loc != NULL)
  4697. {
  4698. memset(sstr ,0, sizeof(sstr) );
  4699. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4700. {
  4701. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4702. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4703. c++;
  4704. }
  4705. sstr[c] = '\0';
  4706. tempminChargingRateFloat = atof(sstr);
  4707. }
  4708. else
  4709. {
  4710. tempminChargingRateFloat = 0.0;
  4711. }
  4712. #if 0
  4713. //
  4714. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4715. tp.tm_isdst = -1;
  4716. time_t utc = mktime(&tp);
  4717. // current time
  4718. time_t t = time(NULL);
  4719. //diff_t = difftime(t, utc);
  4720. #endif
  4721. //parsing strings to words
  4722. i = 0;
  4723. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4724. loc = loc+3+strlen("chargingSchedulePeriod");
  4725. pch = strtok(loc ,"{");
  4726. while (pch != NULL)
  4727. {
  4728. strcpy(SchedulePeriodList[i], pch);
  4729. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4730. //printf ("%s\n",pch);
  4731. pch = strtok (NULL, "{");
  4732. i = i + 1;
  4733. }
  4734. n_SchedulePeriods = i;
  4735. for(int i=0;i<n_SchedulePeriods;i++)
  4736. {
  4737. //*************startPeriod****************/
  4738. c = 0;
  4739. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4740. memset(sstr ,0, sizeof(sstr) );
  4741. while (loc[strlen("startPeriod")+2+c] != ',')
  4742. {
  4743. sstr[c] = loc[strlen("startPeriod")+2+c];
  4744. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4745. c++;
  4746. }
  4747. sstr[c] = '\0';
  4748. tempStartPeriodInt = atoi(sstr);
  4749. //*************limit****************/
  4750. c = 0;
  4751. loc = strstr(SchedulePeriodList[i], "limit");
  4752. memset(sstr ,0, sizeof(sstr) );
  4753. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  4754. {
  4755. sstr[c] = loc[strlen("limit")+2+c];
  4756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4757. c++;
  4758. }
  4759. sstr[c] = '\0';
  4760. tempLimitInt = atof(sstr);
  4761. //*************numberPhases****************/
  4762. c = 0;
  4763. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4764. memset(sstr ,0, sizeof(sstr) );
  4765. if(loc != NULL)
  4766. {
  4767. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4768. {
  4769. sstr[c] = loc[strlen("numberPhases")+2+c];
  4770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4771. c++;
  4772. }
  4773. sstr[c] = '\0';
  4774. tempNumberPhasesInt = atoi(sstr);
  4775. }
  4776. else
  4777. {
  4778. tempNumberPhasesInt = 0;
  4779. }
  4780. TxDefaultProfile.Duration = durationInt;
  4781. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4782. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4783. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4784. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4785. }
  4786. if(MinChargingRate < tempminChargingRateFloat)
  4787. MinChargingRate = tempminChargingRateFloat;
  4788. }
  4789. }
  4790. }// the end of ACCESS TxDefaultProfile
  4791. //--------------------- Composite Schedule-----------------------------//
  4792. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4793. {
  4794. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4795. struct tm tp;
  4796. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4797. tp.tm_isdst = -1;
  4798. time_t utc = mktime(&tp);
  4799. time_t t = time(NULL);
  4800. double diff_f = difftime(t, utc);
  4801. int diff_i; //= (int)diff_f;
  4802. int quotient; //= diff_i / 86400;//86400 seconds/day
  4803. int period = 0;
  4804. if(diff_f >= 0)
  4805. {
  4806. diff_i = (int)diff_f;
  4807. quotient = diff_i / 86400;
  4808. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4809. {
  4810. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4811. {
  4812. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4813. {
  4814. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4815. }
  4816. else
  4817. {
  4818. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4819. }
  4820. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4821. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4822. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4823. period = period + 1;
  4824. }
  4825. }
  4826. }
  4827. confirmPeriods = period;
  4828. }
  4829. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4830. {
  4831. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4832. struct tm tp;
  4833. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4834. tp.tm_isdst = -1;
  4835. time_t utc = mktime(&tp);
  4836. time_t t = time(NULL);
  4837. double diff_f = difftime(t, utc);
  4838. int diff_i; // = (int)diff_f;
  4839. int quotient; // = diff_i / 86400;//86400 seconds/day
  4840. int period = 0;
  4841. if(diff_f >= 0)
  4842. {
  4843. diff_i = (int)diff_f;
  4844. quotient = diff_i / 86400;//86400 seconds/day
  4845. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4846. {
  4847. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4848. {
  4849. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4850. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4851. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4852. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4853. period = period + 1;
  4854. }
  4855. }
  4856. }
  4857. confirmPeriods = period;
  4858. }
  4859. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4860. {
  4861. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4862. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4863. {
  4864. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4865. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4866. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4867. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4868. }
  4869. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4870. }
  4871. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4872. {
  4873. confirmPeriods = 0;
  4874. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4875. goto end;
  4876. }
  4877. //* Define temporary variables */
  4878. struct tm *gtime;
  4879. time_t now;
  4880. char buf[28];
  4881. /* Read the current system time */
  4882. time(&now);
  4883. /* Convert the system time to GMT (now UTC) */
  4884. gtime = gmtime(&now);
  4885. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4886. // make .conf
  4887. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4888. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4889. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4890. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4891. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4892. }
  4893. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4894. {
  4895. //*****************************ChargePointMaxProfile******************************************/
  4896. strcpy(fname, ChargePointMaxProfile_JSON);
  4897. ChargePointMaxProfileIsNull=TRUE;
  4898. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4899. {
  4900. fptr1 = fopen(fname, "r");
  4901. int c;
  4902. c = fgetc(fptr1);
  4903. //DEBUG_INFO("c:%d\n",c);
  4904. rewind(fptr1);
  4905. if(c == EOF)
  4906. {
  4907. DEBUG_INFO("\n End of file reached.");
  4908. ChargePointMaxProfileIsNull=TRUE;
  4909. fclose(fptr1);
  4910. }
  4911. else
  4912. {
  4913. ChargePointMaxProfileIsNull=FALSE;
  4914. while(fscanf(fptr1, "%s", word) != EOF)
  4915. {
  4916. if(strcmp(word, "chargingProfileId") == 0)
  4917. {
  4918. n_chargingProfile = n_chargingProfile + 1;
  4919. }
  4920. }
  4921. rewind(fptr1);
  4922. //search Charging Profile Element
  4923. int i = 0;
  4924. int j = 0;
  4925. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4926. #if 0
  4927. /***********connectorId****************/
  4928. c = 0;
  4929. loc = strstr(sLineWord, "connectorId");
  4930. memset(sstr ,0, sizeof(sstr) );
  4931. while (loc[strlen("connectorId")+2+c] != ',')
  4932. {
  4933. sstr[c] = loc[strlen("connectorId")+2+c];
  4934. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4935. c++;
  4936. }
  4937. sstr[c] = '\0';
  4938. tempconnectorIdInt = atoi(sstr);
  4939. #endif
  4940. //***********validFrom**************/
  4941. c = 0;
  4942. loc = strstr(sLineWord, "validFrom");
  4943. if(loc != NULL)
  4944. {
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while (loc[3+strlen("validFrom")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("validFrom")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(tempvalidFromStr,sstr);
  4953. }
  4954. else
  4955. {
  4956. strcpy(tempvalidFromStr,"");
  4957. }
  4958. //***********validFrom**************/
  4959. c = 0;
  4960. loc = strstr(sLineWord, "duration");
  4961. if(loc != NULL)
  4962. {
  4963. memset(sstr ,0, sizeof(sstr) );
  4964. while (loc[2+strlen("duration")+c] != ',')
  4965. {
  4966. sstr[c] = loc[2+strlen("duration")+c];
  4967. c++;
  4968. }
  4969. sstr[c] = '\0';
  4970. tempdurationInt = atoi(sstr);
  4971. }
  4972. else
  4973. {
  4974. tempdurationInt = 0;
  4975. }
  4976. //**********startSchedule**********/
  4977. c = 0;
  4978. loc = strstr(sLineWord, "startSchedule");
  4979. memset(sstr ,0, sizeof(sstr) );
  4980. while (loc[3+strlen("startSchedule")+c] != '\"')
  4981. {
  4982. sstr[c] = loc[3+strlen("startSchedule")+c];
  4983. c++;
  4984. }
  4985. sstr[c] = '\0';
  4986. strcpy(tempstartScheduleStr, sstr);
  4987. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4988. //**********chargingRateUnit**********/
  4989. c = 0;
  4990. loc = strstr(sLineWord, "chargingRateUnit");
  4991. memset(sstr ,0, sizeof(sstr) );
  4992. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4993. {
  4994. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4995. c++;
  4996. }
  4997. sstr[c] = '\0';
  4998. strcpy(tempchargingRateUnitStr, sstr);
  4999. //**********minChargingRate*******/
  5000. c = 0;
  5001. loc = strstr(sLineWord, "minChargingRate");
  5002. if(loc != NULL)
  5003. {
  5004. memset(sstr ,0, sizeof(sstr) );
  5005. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5006. {
  5007. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5008. c++;
  5009. }
  5010. sstr[c] = '\0';
  5011. tempminChargingRateFloat = atof(sstr);
  5012. }
  5013. else
  5014. {
  5015. tempminChargingRateFloat = 0.0;
  5016. }
  5017. #if 0
  5018. //
  5019. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5020. tp.tm_isdst = -1;
  5021. time_t utc = mktime(&tp);
  5022. time_t t = time(NULL);
  5023. //diff_t = difftime(t, utc);
  5024. #endif
  5025. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5026. //DEBUG_INFO(" debug 5 -1\n");
  5027. //parsing strings to words
  5028. i = 0;
  5029. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5030. loc = loc+3+strlen("chargingSchedulePeriod");
  5031. pch = strtok(loc ,"{");
  5032. while (pch != NULL)
  5033. {
  5034. strcpy(SchedulePeriodList[i], pch);
  5035. pch = strtok (NULL, "{");
  5036. i = i + 1;
  5037. }
  5038. n_SchedulePeriods = i;
  5039. for(int i=0;i<n_SchedulePeriods;i++)
  5040. {
  5041. //*************startPeriod****************/
  5042. c = 0;
  5043. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5044. memset(sstr ,0, sizeof(sstr) );
  5045. while (loc[strlen("startPeriod")+2+c] != ',')
  5046. {
  5047. sstr[c] = loc[strlen("startPeriod")+2+c];
  5048. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5049. c++;
  5050. }
  5051. sstr[c] = '\0';
  5052. tempStartPeriodInt = atoi(sstr);
  5053. //*************limit****************/
  5054. c = 0;
  5055. loc = strstr(SchedulePeriodList[i], "limit");
  5056. memset(sstr ,0, sizeof(sstr) );
  5057. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5058. {
  5059. sstr[c] = loc[strlen("limit")+2+c];
  5060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5061. c++;
  5062. }
  5063. sstr[c] = '\0';
  5064. tempLimitInt = atof(sstr);
  5065. //*************numberPhases****************/
  5066. c = 0;
  5067. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5068. memset(sstr ,0, sizeof(sstr) );
  5069. if(loc != NULL)
  5070. {
  5071. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5072. {
  5073. sstr[c] = loc[strlen("numberPhases")+2+c];
  5074. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5075. c++;
  5076. }
  5077. sstr[c] = '\0';
  5078. tempNumberPhasesInt = atoi(sstr);
  5079. }
  5080. else
  5081. {
  5082. tempNumberPhasesInt = 0;
  5083. }
  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. memset(fname, 0, sizeof fname);
  5108. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5109. TxDefaultProfileFileIsNull=TRUE;
  5110. if((access(fname,F_OK))!=-1)
  5111. {
  5112. fptr1 = fopen(fname, "r");
  5113. c = 0;
  5114. c = fgetc(fptr1);
  5115. //DEBUG_INFO("c:%d\n",c);
  5116. rewind(fptr1);
  5117. if(c == EOF)
  5118. {
  5119. DEBUG_INFO("\n End of file reached.");
  5120. TxDefaultProfileFileIsNull=TRUE;
  5121. fclose(fptr1);
  5122. }
  5123. else
  5124. {
  5125. TxDefaultProfileFileIsNull=FALSE;
  5126. while(fscanf(fptr1, "%s", word) != EOF)
  5127. {
  5128. if(strcmp(word, "chargingProfileId") == 0)
  5129. {
  5130. n_chargingProfile = n_chargingProfile + 1;
  5131. }
  5132. }
  5133. rewind(fptr1);
  5134. //search Charging Profile Element
  5135. int i = 0;
  5136. int j = 0;
  5137. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5138. //DEBUG_INFO(" 1-1\n");
  5139. #if 0
  5140. /***********connectorId****************/
  5141. c = 0;
  5142. loc = strstr(sLineWord, "connectorId");
  5143. memset(sstr ,0, sizeof(sstr) );
  5144. while (loc[strlen("connectorId")+2+c] != ',')
  5145. {
  5146. sstr[c] = loc[strlen("connectorId")+2+c];
  5147. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5148. c++;
  5149. }
  5150. sstr[c] = '\0';
  5151. tempconnectorIdInt = atoi(sstr);
  5152. #endif
  5153. //***********validFrom**************/
  5154. c = 0;
  5155. loc = strstr(sLineWord, "validFrom");
  5156. if(loc != NULL)
  5157. {
  5158. memset(sstr ,0, sizeof(sstr) );
  5159. while (loc[3+strlen("validFrom")+c] != '\"')
  5160. {
  5161. sstr[c] = loc[3+strlen("validFrom")+c];
  5162. c++;
  5163. }
  5164. sstr[c] = '\0';
  5165. strcpy(tempvalidFromStr,sstr);
  5166. }
  5167. else
  5168. {
  5169. strcpy(tempvalidFromStr,"");
  5170. }
  5171. //***********validFrom**************/
  5172. c = 0;
  5173. loc = strstr(sLineWord, "duration");
  5174. if(loc != NULL)
  5175. {
  5176. memset(sstr ,0, sizeof(sstr) );
  5177. while (loc[2+strlen("duration")+c] != ',')
  5178. {
  5179. sstr[c] = loc[2+strlen("duration")+c];
  5180. c++;
  5181. }
  5182. sstr[c] = '\0';
  5183. tempdurationInt = atoi(sstr);
  5184. }
  5185. else
  5186. {
  5187. tempdurationInt = 0;
  5188. }
  5189. //**********startSchedule**********/
  5190. c = 0;
  5191. loc = strstr(sLineWord, "startSchedule");
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[3+strlen("startSchedule")+c] != '\"')
  5194. {
  5195. sstr[c] = loc[3+strlen("startSchedule")+c];
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. strcpy(tempstartScheduleStr, sstr);
  5200. strcpy(TxDefaultProfileScheduleStr, sstr);
  5201. //**********chargingRateUnit**********/
  5202. c = 0;
  5203. loc = strstr(sLineWord, "chargingRateUnit");
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5206. {
  5207. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5208. c++;
  5209. }
  5210. sstr[c] = '\0';
  5211. strcpy(tempchargingRateUnitStr, sstr);
  5212. //**********minChargingRate*******/
  5213. c = 0;
  5214. loc = strstr(sLineWord, "minChargingRate");
  5215. if(loc != NULL)
  5216. {
  5217. memset(sstr ,0, sizeof(sstr) );
  5218. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5219. {
  5220. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5221. c++;
  5222. }
  5223. sstr[c] = '\0';
  5224. tempminChargingRateFloat = atof(sstr);
  5225. }
  5226. else
  5227. {
  5228. tempminChargingRateFloat = 0.0;
  5229. }
  5230. #if 0
  5231. //
  5232. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5233. tp.tm_isdst = -1;
  5234. time_t utc = mktime(&tp);
  5235. time_t t = time(NULL);
  5236. //diff_t = difftime(t, utc);
  5237. #endif
  5238. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5239. //parsing strings to words
  5240. i = 0;
  5241. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5242. loc = loc+3+strlen("chargingSchedulePeriod");
  5243. pch = strtok(loc ,"{");
  5244. while (pch != NULL)
  5245. {
  5246. strcpy(SchedulePeriodList[i], pch);
  5247. pch = strtok (NULL, "{");
  5248. i = i + 1;
  5249. }
  5250. n_SchedulePeriods = i;
  5251. for(int i=0;i<n_SchedulePeriods;i++)
  5252. {
  5253. //*************startPeriod****************/
  5254. c = 0;
  5255. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5256. memset(sstr ,0, sizeof(sstr) );
  5257. while (loc[strlen("startPeriod")+2+c] != ',')
  5258. {
  5259. sstr[c] = loc[strlen("startPeriod")+2+c];
  5260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5261. c++;
  5262. }
  5263. sstr[c] = '\0';
  5264. tempStartPeriodInt = atoi(sstr);
  5265. //*************limit****************/
  5266. c = 0;
  5267. loc = strstr(SchedulePeriodList[i], "limit");
  5268. memset(sstr ,0, sizeof(sstr) );
  5269. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5270. {
  5271. sstr[c] = loc[strlen("limit")+2+c];
  5272. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5273. c++;
  5274. }
  5275. sstr[c] = '\0';
  5276. tempLimitInt = atof(sstr);
  5277. //*************numberPhases****************/
  5278. c = 0;
  5279. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5280. memset(sstr ,0, sizeof(sstr) );
  5281. if(loc != NULL)
  5282. {
  5283. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5284. {
  5285. sstr[c] = loc[strlen("numberPhases")+2+c];
  5286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5287. c++;
  5288. }
  5289. sstr[c] = '\0';
  5290. tempNumberPhasesInt = atoi(sstr);
  5291. }
  5292. else
  5293. {
  5294. tempNumberPhasesInt = 0;
  5295. }
  5296. if(j == 0)
  5297. {
  5298. TxDefaultProfile.Duration = tempdurationInt;
  5299. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5300. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5301. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5302. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5303. }
  5304. else
  5305. {
  5306. //other stack level charging Profile
  5307. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5308. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5309. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5310. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5311. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5312. }
  5313. }
  5314. if(MinChargingRate < tempminChargingRateFloat)
  5315. MinChargingRate = tempminChargingRateFloat;
  5316. if(confirmPeriods < n_SchedulePeriods)
  5317. confirmPeriods = n_SchedulePeriods;
  5318. j = j + 1;
  5319. //DEBUG_INFO(" 1-2\n");
  5320. }
  5321. fclose(fptr1);
  5322. //Stacking Charging Profiles
  5323. for(int l=0; l <(j-1) ;l++)
  5324. {
  5325. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5326. {
  5327. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5328. {
  5329. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5330. {
  5331. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5332. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5333. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5334. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5335. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5336. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5337. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5338. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5339. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5340. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5341. }
  5342. else
  5343. {
  5344. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5345. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5346. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5347. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5348. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5349. }
  5350. }
  5351. }
  5352. }
  5353. //end of Stacking Charging Profiles
  5354. }
  5355. }// the end of ACCESS TxDefaultProfile
  5356. //****************************TxProfile************************************************/
  5357. memset(fname, 0, sizeof fname);
  5358. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5359. TxProfileIsNull=TRUE;
  5360. if((access(fname,F_OK))!=-1)
  5361. {
  5362. fptr1 = fopen(fname, "r");
  5363. c = 0;
  5364. c = fgetc(fptr1);
  5365. //DEBUG_INFO("c:%d\n",c);
  5366. rewind(fptr1);
  5367. if(c == EOF)
  5368. {
  5369. DEBUG_INFO("\n End of file reached.");
  5370. TxProfileIsNull=TRUE;
  5371. fclose(fptr1);
  5372. }
  5373. else
  5374. {
  5375. TxProfileIsNull=FALSE;
  5376. while(fscanf(fptr1, "%s", word) != EOF)
  5377. {
  5378. if(strcmp(word, "chargingProfileId") == 0)
  5379. {
  5380. n_chargingProfile = n_chargingProfile + 1;
  5381. }
  5382. }
  5383. rewind(fptr1);
  5384. //search Charging Profile Element
  5385. int i= 0;
  5386. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5387. #if 0
  5388. /***********connectorId****************/
  5389. c = 0;
  5390. loc = strstr(sLineWord, "connectorId");
  5391. memset(sstr ,0, sizeof(sstr) );
  5392. while (loc[strlen("connectorId")+2+c] != ',')
  5393. {
  5394. sstr[c] = loc[strlen("connectorId")+2+c];
  5395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5396. c++;
  5397. }
  5398. sstr[c] = '\0';
  5399. tempconnectorIdInt = atoi(sstr);
  5400. #endif
  5401. //***********validFrom**************/
  5402. c = 0;
  5403. loc = strstr(sLineWord, "validFrom");
  5404. if(loc != NULL)
  5405. {
  5406. memset(sstr ,0, sizeof(sstr) );
  5407. while (loc[3+strlen("validFrom")+c] != '\"')
  5408. {
  5409. sstr[c] = loc[3+strlen("validFrom")+c];
  5410. c++;
  5411. }
  5412. sstr[c] = '\0';
  5413. strcpy(tempvalidFromStr,sstr);
  5414. }
  5415. else
  5416. {
  5417. strcpy(tempvalidFromStr,"");
  5418. }
  5419. //**********startSchedule**********/
  5420. c = 0;
  5421. loc = strstr(sLineWord, "startSchedule");
  5422. memset(sstr ,0, sizeof(sstr) );
  5423. while (loc[3+strlen("startSchedule")+c] != '\"')
  5424. {
  5425. sstr[c] = loc[3+strlen("startSchedule")+c];
  5426. c++;
  5427. }
  5428. sstr[c] = '\0';
  5429. strcpy(tempstartScheduleStr, sstr);
  5430. strcpy(TxProfileScheduleStr, sstr);
  5431. //**********chargingRateUnit**********/
  5432. c = 0;
  5433. loc = strstr(sLineWord, "chargingRateUnit");
  5434. memset(sstr ,0, sizeof(sstr) );
  5435. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5436. {
  5437. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5438. c++;
  5439. }
  5440. sstr[c] = '\0';
  5441. strcpy(tempchargingRateUnitStr, sstr);
  5442. //**********minChargingRate*******/
  5443. c = 0;
  5444. loc = strstr(sLineWord, "minChargingRate");
  5445. if(loc != NULL)
  5446. {
  5447. memset(sstr ,0, sizeof(sstr) );
  5448. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5449. {
  5450. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5451. c++;
  5452. }
  5453. sstr[c] = '\0';
  5454. tempminChargingRateFloat = atof(sstr);
  5455. }
  5456. else
  5457. {
  5458. tempminChargingRateFloat = 0.0;
  5459. }
  5460. #if 0
  5461. //
  5462. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5463. tp.tm_isdst = -1;
  5464. time_t utc = mktime(&tp);
  5465. time_t t = time(NULL);
  5466. //diff_t = difftime(t, utc);
  5467. #endif
  5468. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5469. //parsing strings to words
  5470. i = 0;
  5471. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5472. loc = loc+3+strlen("chargingSchedulePeriod");
  5473. pch = strtok(loc ,"{");
  5474. while (pch != NULL)
  5475. {
  5476. strcpy(SchedulePeriodList[i], pch);
  5477. pch = strtok (NULL, "{");
  5478. i = i + 1;
  5479. }
  5480. n_SchedulePeriods = i;
  5481. for(int i=0;i<n_SchedulePeriods;i++)
  5482. {
  5483. //*************startPeriod****************/
  5484. c = 0;
  5485. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5486. memset(sstr ,0, sizeof(sstr) );
  5487. while (loc[strlen("startPeriod")+2+c] != ',')
  5488. {
  5489. sstr[c] = loc[strlen("startPeriod")+2+c];
  5490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5491. c++;
  5492. }
  5493. sstr[c] = '\0';
  5494. tempStartPeriodInt = atoi(sstr);
  5495. //*************limit****************/
  5496. c = 0;
  5497. loc = strstr(SchedulePeriodList[i], "limit");
  5498. memset(sstr ,0, sizeof(sstr) );
  5499. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5500. {
  5501. sstr[c] = loc[strlen("limit")+2+c];
  5502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5503. c++;
  5504. }
  5505. sstr[c] = '\0';
  5506. tempLimitInt = atof(sstr);
  5507. //*************numberPhases****************/
  5508. c = 0;
  5509. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5510. memset(sstr ,0, sizeof(sstr) );
  5511. if(loc != NULL)
  5512. {
  5513. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5514. {
  5515. sstr[c] = loc[strlen("numberPhases")+2+c];
  5516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5517. c++;
  5518. }
  5519. sstr[c] = '\0';
  5520. tempNumberPhasesInt = atoi(sstr);
  5521. }
  5522. else
  5523. {
  5524. tempNumberPhasesInt = 0;
  5525. }
  5526. TxProfile.Duration = durationInt;
  5527. TxProfile.TotalPeriod = n_SchedulePeriods;
  5528. TxProfile.Period[i].Limit = tempLimitInt;
  5529. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5530. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5531. }
  5532. if(MinChargingRate < tempminChargingRateFloat)
  5533. MinChargingRate = tempminChargingRateFloat;
  5534. if(confirmPeriods < n_SchedulePeriods)
  5535. confirmPeriods = n_SchedulePeriods;
  5536. }
  5537. fclose(fptr1);
  5538. }
  5539. }// the end of ACCESS TxProfile
  5540. //CompositeSchedule
  5541. int period=0;
  5542. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5543. {
  5544. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5545. struct tm tp;
  5546. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5547. tp.tm_isdst = -1;
  5548. time_t utc = mktime(&tp);
  5549. time_t t = time(NULL);
  5550. double diff_f = difftime(t, utc);
  5551. int diff_i; // = (int)diff_f;
  5552. int quotient; // = diff_i / 86400;//86400 seconds/day
  5553. //int remainder = diff_i % 86400;
  5554. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5555. {
  5556. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5557. {
  5558. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5559. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5560. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5561. period = period + 1;
  5562. }
  5563. else
  5564. {
  5565. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5566. {
  5567. }
  5568. else
  5569. {
  5570. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5571. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5572. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5573. period = period + 1;
  5574. }
  5575. }
  5576. }
  5577. if( diff_f >= 0)
  5578. {
  5579. diff_i = (int)diff_f;
  5580. quotient = diff_i / 86400;//86400 seconds/day
  5581. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5582. {
  5583. 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))
  5584. {
  5585. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5586. {
  5587. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5588. }
  5589. else
  5590. {
  5591. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5592. }
  5593. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5594. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5595. period = period + 1;
  5596. }
  5597. }
  5598. // Check Last Period
  5599. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5600. {
  5601. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5602. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5604. period = period + 1;
  5605. }
  5606. } // diff_f >= 0
  5607. }
  5608. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5609. {
  5610. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5611. struct tm tp;
  5612. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5613. tp.tm_isdst = -1;
  5614. time_t utc = mktime(&tp);
  5615. time_t t = time(NULL);
  5616. double diff_f = difftime(t, utc);
  5617. int diff_i;// = (int)diff_f;
  5618. int quotient; // = diff_i / 86400;//86400 seconds/day
  5619. //int remainder = diff_i % 86400;
  5620. if(diff_f >= 0)
  5621. {
  5622. diff_i = (int)diff_f;
  5623. quotient = diff_i / 86400;//86400 seconds/day
  5624. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5625. {
  5626. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5627. {
  5628. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5629. {
  5630. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5631. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5632. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5633. period = period + 1;
  5634. }
  5635. else
  5636. {
  5637. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5638. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5639. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5640. period = period + 1;
  5641. }
  5642. }
  5643. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5644. {
  5645. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5646. {
  5647. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5648. {
  5649. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5650. {
  5651. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5652. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5653. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5654. period = period + 1;
  5655. }
  5656. else
  5657. {
  5658. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5659. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5660. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5661. period = period + 1;
  5662. }
  5663. }
  5664. }
  5665. }
  5666. }
  5667. } // end diff_f >= 0
  5668. }
  5669. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5670. {
  5671. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5672. struct tm tp;
  5673. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5674. tp.tm_isdst = -1;
  5675. time_t utc = mktime(&tp);
  5676. time_t t = time(NULL);
  5677. double diff_f = difftime(t, utc);
  5678. int diff_i; // = (int)diff_f;
  5679. int quotient; // = diff_i / 86400;//86400 seconds/day
  5680. //int remainder = diff_i % 86400;
  5681. if(diff_f >= 0)
  5682. {
  5683. diff_i = (int)diff_f;
  5684. quotient = diff_i / 86400;//86400 seconds/day
  5685. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5686. {
  5687. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5688. {
  5689. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5690. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5691. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5692. period = period + 1;
  5693. }
  5694. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5695. {
  5696. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5697. {
  5698. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5699. {
  5700. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5701. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5702. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5703. period = period + 1;
  5704. }
  5705. }
  5706. }
  5707. }
  5708. } // diff_f >= 0
  5709. }
  5710. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5711. {
  5712. confirmPeriods = 0;
  5713. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5714. goto end;
  5715. }
  5716. confirmPeriods = period;
  5717. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5718. //---- Define StartSchedule----/
  5719. struct tm *gtime;
  5720. time_t now;
  5721. char buf[28];
  5722. //---Read the current system time---/
  5723. time(&now);
  5724. //---Convert the system time to GMT (now UTC)---/
  5725. gtime = gmtime(&now);
  5726. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5727. // make .conf
  5728. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5729. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5730. //DEBUG_INFO(" debug 11\n");
  5731. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5732. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5733. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5734. }
  5735. else
  5736. {
  5737. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5738. }
  5739. end:
  5740. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5741. return result;
  5742. }
  5743. int handleGetConfigurationRequest(char *uuid, char *payload)
  5744. {
  5745. mtrace();
  5746. int result = FAIL;
  5747. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5748. //struct json_object *jsonitem;
  5749. int MaxKeySupported = 0;
  5750. int n_keys = 0;
  5751. char requestKey[43][50]={0};
  5752. char search[]="[";
  5753. char sstr[500]={ 0 };
  5754. //int pos;
  5755. int l, c = 0;
  5756. int i = 0;
  5757. char *delim = "\",\"";
  5758. char * pch;
  5759. char *loc = strstr(payload, search);
  5760. //********************* Parsing String ***********************************/
  5761. if(loc == NULL) {
  5762. DEBUG_INFO("no key match in Configuration \n");
  5763. }
  5764. else {
  5765. //pos = loc - payload;
  5766. l = strlen(loc)-4;
  5767. while (c < l)
  5768. {
  5769. sstr[c] = loc[c+2];
  5770. c++;
  5771. }
  5772. sstr[c] = '\0';
  5773. //parsing strings to words
  5774. pch = strtok(sstr,delim);
  5775. if(pch == NULL)
  5776. {
  5777. strcpy(requestKey[0], sstr);
  5778. }
  5779. else
  5780. {
  5781. while (pch != NULL)
  5782. {
  5783. strcpy(requestKey[i], pch);
  5784. pch = strtok (NULL, delim);
  5785. i = i + 1;
  5786. }
  5787. n_keys = i;
  5788. }
  5789. }
  5790. UnknownKeynum = 0;
  5791. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5792. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5793. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5794. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5795. if(n_keys != 0)
  5796. {
  5797. for(int i=0;i<n_keys;i++)
  5798. {
  5799. getKeyValue(requestKey[i]);
  5800. //json_object_put(jsonitem);
  5801. }
  5802. }
  5803. else
  5804. {
  5805. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5806. getKeyValue("");
  5807. }
  5808. processUnkownKey();
  5809. sendGetConfigurationConfirmation(uuid);
  5810. return result;
  5811. }
  5812. static char fnamePlusPath[100]={0};
  5813. static char fnamePWithNoPath[60]={0};
  5814. void checkUploadLog(void)
  5815. {
  5816. FILE *fp;
  5817. /* Open the command for reading. */
  5818. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5819. if (fp == NULL) {
  5820. printf("Failed to run command\n" );
  5821. exit(1);
  5822. }
  5823. int ftppathlen = 0;
  5824. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5825. int i = 0;
  5826. /* Read the output a line at a time - output it. */
  5827. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5828. if(i==0)
  5829. {
  5830. ftppathlen = strlen(fnamePlusPath);
  5831. printf("%s\n", fnamePlusPath);
  5832. fnamePlusPath[ftppathlen]='\0';
  5833. break;
  5834. }
  5835. i= i+1;
  5836. }
  5837. /* close */
  5838. pclose(fp);
  5839. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5840. {
  5841. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5842. {
  5843. fnamePlusPath[k]='\0';
  5844. }
  5845. }
  5846. i=1;
  5847. //char fname[60]={0};
  5848. while(i < ftppathlen)
  5849. {
  5850. int len=ftppathlen-i;
  5851. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5852. {
  5853. printf("compare '/' all right\n");
  5854. break;
  5855. }
  5856. i=i+1;
  5857. }
  5858. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5859. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5860. fnamePWithNoPath[i+1] = '\0';
  5861. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5862. {
  5863. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5864. {
  5865. fnamePWithNoPath[j]='\0';
  5866. }
  5867. }
  5868. FILE* fp1 = fopen(fnamePlusPath, "r");
  5869. if (fp1)
  5870. {
  5871. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5872. // file exists
  5873. fclose(fp1);
  5874. }
  5875. else
  5876. {
  5877. // file doesn't exist
  5878. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5879. }
  5880. }
  5881. static char GetDiagnosticspayloadData[300]={0};
  5882. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5883. {
  5884. mtrace();
  5885. int result = FAIL;
  5886. pthread_t t; // pthread 變數
  5887. system("exec /root/logPackTools 'log' 6");
  5888. #if 0
  5889. //char buffer [128];
  5890. time (&rawtime);
  5891. //printf("%ld\n", rawtime);
  5892. timeinfo = localtime (&rawtime);
  5893. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5894. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5895. if((access(fnamePlusPath,F_OK))!=-1)
  5896. {
  5897. DEBUG_INFO("fnamePlusPath exist.\n");
  5898. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5899. }
  5900. else
  5901. {
  5902. DEBUG_INFO("fnamePlusPath not exist!\n");
  5903. }
  5904. #endif
  5905. checkUploadLog();
  5906. memset(GetDiagnosticspayloadData, 0, 300);
  5907. strcpy(GetDiagnosticspayloadData, payload);
  5908. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5909. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5910. return result;
  5911. }
  5912. void* GetDiagnosticsProcess(void* data)
  5913. {
  5914. pthread_detach(pthread_self());
  5915. mtrace();
  5916. int retriesInt=0, retryIntervalInt=0;
  5917. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5918. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5919. 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};
  5920. int port=0;
  5921. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5922. int c = 0;
  5923. char *loc;
  5924. int isSuccess = FALSE;
  5925. char ftpbuf[200]={0};
  5926. //char temp[100]={0};
  5927. char * pch;
  5928. // [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"}]
  5929. char str[300]={ 0 };
  5930. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5931. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5932. DEBUG_INFO("GetDiagnosticsProcess\n");
  5933. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5934. //****************location*******************/
  5935. c = 0;
  5936. memset(sstr ,0, sizeof(sstr) );
  5937. loc = strstr(str, "location");
  5938. while (loc[3+strlen("location")+c] != '\"')
  5939. {
  5940. sstr[c] = loc[3+strlen("location")+c];
  5941. c++;
  5942. }
  5943. sstr[c] = '\0';
  5944. strcpy(locationstr,sstr);
  5945. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5946. if(strcmp(locationstr,"")==0)
  5947. {
  5948. DEBUG_INFO("location is <Empty>!\n");
  5949. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5950. goto end;
  5951. }
  5952. //****************retries*******************/
  5953. c = 0;
  5954. loc = strstr(str, "retries");
  5955. if(loc == NULL)
  5956. {
  5957. retriesIsNULL = TRUE;
  5958. }
  5959. else
  5960. {
  5961. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5962. {
  5963. sstr[c] = loc[strlen("retries")+2+c];
  5964. c++;
  5965. }
  5966. sstr[c] = '\0';
  5967. retriesInt = atoi(sstr);
  5968. }
  5969. if(retriesIsNULL == TRUE)
  5970. {
  5971. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5972. }
  5973. //****************retryInterval*******************/
  5974. c = 0;
  5975. loc = strstr(str, "retryInterval");
  5976. if(loc == NULL)
  5977. {
  5978. retryIntervalIsNULL = TRUE;
  5979. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5980. }
  5981. else
  5982. {
  5983. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5984. {
  5985. sstr[c] = loc[strlen("retryInterval")+2+c];
  5986. c++;
  5987. }
  5988. sstr[c] = '\0';
  5989. retryIntervalInt = atoi(sstr);
  5990. }
  5991. //****************startTime*******************/
  5992. c = 0;
  5993. memset(sstr ,0, sizeof(sstr) );
  5994. loc = strstr(str, "startTime");
  5995. if(loc == NULL)
  5996. {
  5997. startTimeIsNULL = TRUE;
  5998. }
  5999. else
  6000. {
  6001. while (loc[3+strlen("startTime")+c] != '\"')
  6002. {
  6003. sstr[c] = loc[3+strlen("startTime")+c];
  6004. c++;
  6005. }
  6006. sstr[c] = '\0';
  6007. strcpy(startTimestr,sstr);
  6008. }
  6009. //****************stopTime*******************/
  6010. c = 0;
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. loc = strstr(str, "stopTime");
  6013. if(loc == NULL)
  6014. {
  6015. stopTimeIsNULL = TRUE;
  6016. }
  6017. else
  6018. {
  6019. while (loc[3+strlen("stopTime")+c] != '\"')
  6020. {
  6021. sstr[c] = loc[3+strlen("stopTime")+c];
  6022. c++;
  6023. }
  6024. sstr[c] = '\0';
  6025. strcpy(stopTimestr,sstr);
  6026. }
  6027. memset(protocol, 0, sizeof(protocol));
  6028. memset(user, 0, sizeof(user) );
  6029. memset(password, 0, sizeof(password));
  6030. memset(host, 0, sizeof(host));
  6031. memset(path, 0, sizeof(path));
  6032. memset(ftppath, 0, sizeof(ftppath));
  6033. memset(host1, 0, sizeof(host1));
  6034. memset(path1, 0, sizeof(path1));
  6035. /*location: ftp://user:password@host:port/path*/
  6036. #if 0
  6037. time_t rawtime;
  6038. struct tm * timeinfo;
  6039. //char buffer [128];
  6040. time (&rawtime);
  6041. //printf("%ld\n", rawtime);
  6042. timeinfo = localtime (&rawtime);
  6043. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6044. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6045. #endif
  6046. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6047. if((access(fnamePlusPath,F_OK))!=-1)
  6048. {
  6049. DEBUG_INFO("fnamePlusPath exist.\n");
  6050. }
  6051. else
  6052. {
  6053. DEBUG_INFO("fnamePlusPath not exist!\n");
  6054. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6055. goto end;
  6056. }
  6057. pch=strchr(locationstr,'@');
  6058. if(pch==NULL)
  6059. {
  6060. sscanf(locationstr,
  6061. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6062. protocol, host, &port, path);
  6063. strcpy(user,"anonymous");
  6064. strcpy(password,"");
  6065. }
  6066. else
  6067. {
  6068. //DEBUG_INFO("pch=%s\n", pch);
  6069. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6070. protocol, user, password, host, &port, path);
  6071. }
  6072. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6073. {
  6074. DEBUG_INFO("protocol is not ftp/http ! \n");
  6075. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6076. goto end;
  6077. }
  6078. if(strncmp(locationstr,"http", 4) == 0)
  6079. {
  6080. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6081. sprintf(ftppath,"/%s", path);
  6082. do{
  6083. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6084. sleep(retryIntervalInt);
  6085. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6086. if(!isSuccess)
  6087. {
  6088. DEBUG_INFO("Diagnostics fail.\n");
  6089. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6090. }
  6091. else
  6092. {
  6093. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6094. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6095. }
  6096. }
  6097. else
  6098. {
  6099. sscanf(host,"%[^/]%s",host1, path1);
  6100. sprintf(ftppath,"%s", path1);
  6101. int ftppathlen=strlen(ftppath);
  6102. int i=1;
  6103. char filenametemp[50];
  6104. while(i < ftppathlen)
  6105. {
  6106. int len=ftppathlen-i;
  6107. if(ftppath[len]== 47) // '/' ascll code: 47
  6108. {
  6109. DEBUG_INFO("find '/' all right\n");
  6110. break;
  6111. }
  6112. i=i+1;
  6113. }
  6114. memset(filenametemp, 0, sizeof(filenametemp));
  6115. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6116. filenametemp[i+1] = 0;
  6117. memset(ftpbuf, 0, sizeof(ftpbuf));
  6118. if(port == 0)
  6119. port = 21;
  6120. do{
  6121. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6122. sleep(retryIntervalInt);
  6123. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6124. if(!isSuccess)
  6125. {
  6126. DEBUG_INFO("Diagnostics fail.\n");
  6127. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6128. }
  6129. else
  6130. {
  6131. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6132. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6133. }
  6134. }
  6135. end:
  6136. DiagnosticsStatusNotificationStatus = 0; //Idle
  6137. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6138. }
  6139. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6140. {
  6141. mtrace();
  6142. int result = FAIL;
  6143. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6144. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6145. {
  6146. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6147. localversion = -1;
  6148. }
  6149. else
  6150. {
  6151. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6152. OCPP_getListVerion();
  6153. }
  6154. //from db.OCPP_getListVerion
  6155. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6156. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6157. sendGetLocalListVersionConfirmation(uuid,"");
  6158. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6159. return result;
  6160. }
  6161. int handleRemoteStartRequest(char *uuid, char *payload)
  6162. {
  6163. mtrace();
  6164. int result = FAIL;
  6165. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6166. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6167. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6168. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6169. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6170. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6171. int chargingSchedulePeriodCount = 0;
  6172. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6173. int c = 0;
  6174. char *loc;
  6175. char comfirmstr[20]={0};
  6176. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6177. if(server_pending == TRUE)
  6178. {
  6179. return 0;
  6180. }
  6181. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6182. //**********connectorId****************/
  6183. c = 0;
  6184. memset(sstr ,0, sizeof(sstr) );
  6185. loc = strstr(payload, "connectorId");
  6186. if(loc == NULL)
  6187. {
  6188. connectorIdIsNULL = TRUE;
  6189. }
  6190. else
  6191. {
  6192. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6193. {
  6194. sstr[c] = loc[strlen("connectorId")+2+c];
  6195. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6196. c++;
  6197. }
  6198. sstr[c] = '\0';
  6199. connectorIdInt = atoi(sstr);
  6200. }
  6201. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6202. {
  6203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6204. goto end;
  6205. }
  6206. //****************idTag*******************/
  6207. c = 0;
  6208. memset(sstr ,0, sizeof(sstr) );
  6209. loc = strstr(payload, "idTag");
  6210. while (loc[3+strlen("idTag")+c] != '\"')
  6211. {
  6212. sstr[c] = loc[3+strlen("idTag")+c];
  6213. c++;
  6214. }
  6215. sstr[c] = '\0';
  6216. strcpy(idTagstr,sstr);
  6217. //****************chargingProfile*******************/
  6218. c = 0;
  6219. memset(sstr ,0, sizeof(sstr) );
  6220. loc = strstr(payload, "chargingProfile");
  6221. if(loc == NULL)
  6222. {
  6223. chargingProfileIsNULL = TRUE;
  6224. }
  6225. else
  6226. {
  6227. //****************chargingProfileId*******************/
  6228. c=0;
  6229. loc = strstr(payload, "chargingProfileId");
  6230. memset(sstr ,0, sizeof(sstr) );
  6231. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6232. {
  6233. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6235. c++;
  6236. }
  6237. sstr[c] = '\0';
  6238. chargingProfileIdInt = atoi(sstr);
  6239. //****************transactionId*******************/
  6240. loc = strstr(payload, "transactionId");
  6241. if(loc == NULL)
  6242. {
  6243. transactionIdIsNULL = TRUE;
  6244. }
  6245. else
  6246. {
  6247. c=0;
  6248. memset(sstr ,0, sizeof(sstr) );
  6249. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6250. {
  6251. sstr[c] = loc[strlen("transactionId")+2+c];
  6252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6253. c++;
  6254. }
  6255. sstr[c] = '\0';
  6256. transactionIdInt = atoi(sstr);
  6257. }
  6258. //****************stackLevel*******************/
  6259. c=0;
  6260. loc = strstr(payload, "stackLevel");
  6261. memset(sstr ,0, sizeof(sstr) );
  6262. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6263. {
  6264. sstr[c] = loc[strlen("stackLevel")+2+c];
  6265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6266. c++;
  6267. }
  6268. sstr[c] = '\0';
  6269. stackLevelInt = atoi(sstr);
  6270. //****************chargingProfilePurpose*******************/
  6271. c = 0;
  6272. memset(sstr ,0, sizeof(sstr) );
  6273. loc = strstr(payload, "chargingProfilePurpose");
  6274. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6275. {
  6276. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6277. c++;
  6278. }
  6279. sstr[c] = '\0';
  6280. strcpy(chargingProfilePurposestr,sstr);
  6281. //****************chargingProfileKind*******************/
  6282. c = 0;
  6283. memset(sstr ,0, sizeof(sstr) );
  6284. loc = strstr(payload, "chargingProfileKind");
  6285. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6286. {
  6287. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6288. c++;
  6289. }
  6290. sstr[c] = '\0';
  6291. strcpy(chargingProfileKindstr,sstr);
  6292. //****************recurrencyKind*******************/
  6293. loc = strstr(payload, "recurrencyKind");
  6294. if(loc == NULL)
  6295. {
  6296. recurrencyKindIsNULL = TRUE;
  6297. }
  6298. else
  6299. {
  6300. c = 0;
  6301. memset(sstr ,0, sizeof(sstr) );
  6302. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6303. {
  6304. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6305. c++;
  6306. }
  6307. sstr[c] = '\0';
  6308. strcpy(recurrencyKindstr,sstr);
  6309. }
  6310. //****************validFrom*******************/
  6311. loc = strstr(payload, "validFrom");
  6312. if(loc == NULL)
  6313. {
  6314. validFromIsNULL = TRUE;
  6315. }
  6316. else
  6317. {
  6318. c = 0;
  6319. memset(sstr ,0, sizeof(sstr) );
  6320. while (loc[3+strlen("validFrom")+c] != '\"')
  6321. {
  6322. sstr[c] = loc[3+strlen("validFrom")+c];
  6323. c++;
  6324. }
  6325. sstr[c] = '\0';
  6326. strcpy(validFromstr,sstr);
  6327. }
  6328. //****************validTo*******************/
  6329. loc = strstr(payload, "validTo");
  6330. if(loc == NULL)
  6331. {
  6332. validToIsNULL = TRUE;
  6333. }
  6334. else
  6335. {
  6336. c = 0;
  6337. memset(sstr ,0, sizeof(sstr) );
  6338. while (loc[3+strlen("validTo")+c] != '\"')
  6339. {
  6340. sstr[c] = loc[3+strlen("validTo")+c];
  6341. c++;
  6342. }
  6343. sstr[c] = '\0';
  6344. strcpy(validTostr,sstr);
  6345. }
  6346. //****************chargingSchedule*******************/
  6347. loc = strstr(payload, "chargingSchedule");
  6348. if(loc != NULL)
  6349. {
  6350. //****************duration*******************/
  6351. loc = strstr(payload, "duration");
  6352. if(loc == NULL)
  6353. {
  6354. durationIsNULL = TRUE;
  6355. }
  6356. else
  6357. {
  6358. c=0;
  6359. memset(sstr ,0, sizeof(sstr) );
  6360. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6361. {
  6362. sstr[c] = loc[strlen("duration")+2+c];
  6363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6364. c++;
  6365. }
  6366. sstr[c] = '\0';
  6367. durationInt = atoi(sstr);
  6368. }
  6369. //****************startSchedule******************/
  6370. loc = strstr(payload, "startSchedule");
  6371. if(loc == NULL)
  6372. {
  6373. startScheduleIsNULL = TRUE;
  6374. }
  6375. else
  6376. {
  6377. c = 0;
  6378. memset(sstr ,0, sizeof(sstr) );
  6379. while (loc[3+strlen("startSchedule")+c] != '\"')
  6380. {
  6381. sstr[c] = loc[3+strlen("startSchedule")+c];
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. strcpy(startSchedulestr,sstr);
  6386. }
  6387. //****************chargingRateUnit*******************/
  6388. c = 0;
  6389. memset(sstr ,0, sizeof(sstr) );
  6390. loc = strstr(payload, "chargingRateUnit");
  6391. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6392. {
  6393. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6394. c++;
  6395. }
  6396. sstr[c] = '\0';
  6397. strcpy(chargingRateUnitstr,sstr);
  6398. //****************minChargingRate*******************/
  6399. loc = strstr(payload, "minChargingRate");
  6400. if(loc == NULL)
  6401. {
  6402. minChargingRateIsNULL = TRUE;
  6403. }
  6404. else
  6405. {
  6406. c=0;
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6409. {
  6410. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. minChargingRateflaot = atof(sstr);
  6416. }
  6417. //****************chargingSchedulePeriod count*******************/
  6418. int what_len = strlen("startPeriod");
  6419. char *where = payload;
  6420. while ((where = strstr(where, "startPeriod"))) {
  6421. where += what_len;
  6422. chargingSchedulePeriodCount++;
  6423. }
  6424. where = payload;
  6425. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6426. {
  6427. //****************startPeriod*******************/
  6428. c=0;
  6429. loc = strstr(where, "startPeriod");
  6430. memset(sstr ,0, sizeof(sstr) );
  6431. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6432. {
  6433. sstr[c] = loc[strlen("startPeriod")+2+c];
  6434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6435. c++;
  6436. }
  6437. sstr[c] = '\0';
  6438. startPeriodInt[periodNums] = atoi(sstr);
  6439. //****************limit*******************/
  6440. c=0;
  6441. loc = strstr(where, "limit");
  6442. memset(sstr ,0, sizeof(sstr) );
  6443. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6444. {
  6445. sstr[c] = loc[strlen("limit")+2+c];
  6446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6447. c++;
  6448. }
  6449. sstr[c] = '\0';
  6450. limitflaot[periodNums] = atof(sstr);
  6451. //****************numberPhases*******************/
  6452. loc = strstr(where, "numberPhases");
  6453. if(loc == NULL)
  6454. {
  6455. numberPhasesIsNULL = TRUE;
  6456. }
  6457. else
  6458. {
  6459. c=0;
  6460. memset(sstr ,0, sizeof(sstr) );
  6461. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6462. {
  6463. sstr[c] = loc[strlen("numberPhases")+2+c];
  6464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6465. c++;
  6466. }
  6467. sstr[c] = '\0';
  6468. numberPhasesInt[periodNums] = atoi(sstr);
  6469. }
  6470. where = loc;
  6471. }
  6472. }
  6473. }
  6474. /*
  6475. enum _SYSTEM_STATUS
  6476. {
  6477. S_BOOTING = 0,
  6478. S_IDLE, = 1
  6479. S_AUTHORIZING, =2
  6480. S_REASSIGN_CHECK, =3
  6481. S_REASSIGN, =4
  6482. S_PRECHARGE, =5
  6483. S_PREPARING_FOR_EV, =6
  6484. S_PREPARING_FOR_EVSE, =7
  6485. S_CHARGING, =8
  6486. S_TERMINATING, =9
  6487. S_COMPLETE, =10
  6488. S_ALARM, =11
  6489. S_FAULT =12
  6490. }
  6491. */
  6492. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6493. {
  6494. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6495. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6496. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6497. //check Transaction active
  6498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6499. {
  6500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6503. {
  6504. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6505. {
  6506. //Reserved
  6507. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6508. }
  6509. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6510. {
  6511. //Reserved
  6512. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6513. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6514. goto end;
  6515. }
  6516. else
  6517. {
  6518. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6519. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6520. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6521. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6522. {
  6523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6524. goto end;
  6525. }
  6526. }//END FOR ELSE
  6527. }
  6528. }// END FOR CHAdeMO_QUANTITY
  6529. for (int index = 0; index < CCS_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6532. {
  6533. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6534. {
  6535. //Reserved
  6536. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6537. }
  6538. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6539. {
  6540. //Reserved
  6541. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6543. goto end;
  6544. }
  6545. else
  6546. {
  6547. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6548. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6549. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6550. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6551. {
  6552. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6553. goto end;
  6554. }
  6555. }// END FOR ELSE
  6556. }
  6557. }// END FOR CCS_QUANTITY
  6558. for (int index = 0; index < GB_QUANTITY; index++)
  6559. {
  6560. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6561. {
  6562. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6563. {
  6564. //Reserved
  6565. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6566. }
  6567. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6568. {
  6569. //Reserved
  6570. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6572. goto end;
  6573. }
  6574. else
  6575. {
  6576. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6577. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6578. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6579. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6580. {
  6581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6582. goto end;
  6583. }
  6584. }// END FOR ELSE
  6585. }
  6586. } // END FOR GB_QUANTITY
  6587. }
  6588. else
  6589. {
  6590. for (int index = 0; index < AC_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6593. {
  6594. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6595. {
  6596. //Reserved
  6597. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6598. }
  6599. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6600. {
  6601. //Reserved
  6602. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6604. goto end;
  6605. }
  6606. else
  6607. {
  6608. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6609. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6610. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6611. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6612. {
  6613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6614. goto end;
  6615. }
  6616. }//END FOR ELSE
  6617. }
  6618. }// END FOR AC_QUANTITY
  6619. }
  6620. if(chargingProfileIsNULL == FALSE)
  6621. {
  6622. //ChargingProfile
  6623. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6624. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6625. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6626. if(recurrencyKindIsNULL == FALSE) //OPTION
  6627. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6628. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6629. if(transactionIdIsNULL == FALSE) // OPTION
  6630. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6631. if(validFromIsNULL == FALSE) // OPTION
  6632. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6633. if(validToIsNULL == FALSE) //OPTION
  6634. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6635. //ChargingSchedule
  6636. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6637. if(durationIsNULL == FALSE) //OPTION
  6638. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6639. if(minChargingRateIsNULL == FALSE) //OPTION
  6640. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6641. if(startScheduleIsNULL == FALSE) //OPTION
  6642. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6643. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6644. {
  6645. //ChargingSchedulePeriod
  6646. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6647. if(numberPhasesIsNULL == FALSE)
  6648. {
  6649. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6650. }
  6651. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6652. }
  6653. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6654. {
  6655. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6656. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6657. //memset idTag
  6658. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6659. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6660. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6661. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6662. }
  6663. else
  6664. {
  6665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6666. }
  6667. }
  6668. else
  6669. {
  6670. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6671. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6672. //memset idTag
  6673. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6674. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6675. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6676. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6677. }
  6678. }
  6679. else
  6680. {
  6681. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6682. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6683. }
  6684. end:
  6685. if(connectorIdIsNULL == FALSE)
  6686. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6687. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6688. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6689. //OCPP send RemoteStartConfirmation by first.
  6690. sendRemoteStartConfirmation(uuid, comfirmstr);
  6691. return result;
  6692. }
  6693. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6694. {
  6695. mtrace();
  6696. int result = FAIL;
  6697. int match = FALSE;
  6698. int GunNO = 0;
  6699. int transactionIdInt=0;
  6700. int transactionIdIsNULL= FALSE;
  6701. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6702. int c = 0;
  6703. char *loc;
  6704. char comfirmstr[20];
  6705. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6706. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6707. if(server_pending == TRUE)
  6708. {
  6709. return 0;
  6710. }
  6711. c=0;
  6712. loc = strstr(payload, "transactionId");
  6713. if(loc == NULL)
  6714. {
  6715. transactionIdIsNULL= TRUE;
  6716. }
  6717. else
  6718. {
  6719. memset(sstr ,0, sizeof(sstr) );
  6720. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6721. {
  6722. sstr[c] = loc[strlen("transactionId")+2+c];
  6723. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6724. c++;
  6725. }
  6726. sstr[c] = '\0';
  6727. transactionIdInt = atoi(sstr);
  6728. }
  6729. if(transactionIdIsNULL == FALSE)
  6730. {
  6731. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6732. {
  6733. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6734. {
  6735. //check Transaction active
  6736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6737. {
  6738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6739. {
  6740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6741. {
  6742. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6743. {
  6744. match = TRUE;
  6745. GunNO = gun_index;
  6746. }
  6747. }
  6748. }// END FOR CHAdeMO_QUANTITY
  6749. for (int index = 0; index < CCS_QUANTITY; index++)
  6750. {
  6751. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6752. {
  6753. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6754. {
  6755. match = TRUE;
  6756. GunNO = gun_index;
  6757. }
  6758. }
  6759. }// END FOR CCS_QUANTITY
  6760. for (int index = 0; index < GB_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6763. {
  6764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6765. {
  6766. match = TRUE;
  6767. GunNO = gun_index;
  6768. }
  6769. }
  6770. }// END FOR GB_QUANTITY
  6771. }
  6772. else
  6773. {
  6774. for (int index = 0; index < AC_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6777. {
  6778. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6779. {
  6780. match = TRUE;
  6781. GunNO = gun_index;
  6782. }
  6783. }
  6784. }// END FOR CHAdeMO_QUANTITY
  6785. }// END FOR AC ELSE
  6786. }// CHECK IF ResponseTransactionId == transactionIdInt
  6787. }//END FOR
  6788. if( match == TRUE)
  6789. {
  6790. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6791. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6792. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6793. }
  6794. else
  6795. {
  6796. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6797. }
  6798. }
  6799. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6800. return result;
  6801. }
  6802. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6803. {
  6804. mtrace();
  6805. int result = FAIL;
  6806. int connectorIdInt=0, reservationIdInt=0;
  6807. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6808. char comfirmstr[20]={0};
  6809. char sstr[180]={ 0 };
  6810. int c = 0;
  6811. char *loc;
  6812. //char *ptr;
  6813. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6814. //***(1)connectorId ****/
  6815. c=0;
  6816. loc = strstr(payload, "connectorId");
  6817. memset(sstr ,0, sizeof(sstr) );
  6818. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6819. {
  6820. sstr[c] = loc[strlen("connectorId")+2+c];
  6821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6822. c++;
  6823. }
  6824. sstr[c] = '\0';
  6825. connectorIdInt = atoi(sstr);
  6826. //***(2)expiryDate ****/
  6827. loc = strstr(payload, "expiryDate");
  6828. memset(sstr ,0, sizeof(sstr) );
  6829. c = 0;
  6830. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6831. {
  6832. sstr[c] = loc[3+strlen("expiryDate")+c];
  6833. c++;
  6834. }
  6835. sstr[c] = '\0';
  6836. strcpy(expiryDatestr, sstr);
  6837. //***(3)idTag ****/
  6838. loc = strstr(payload, "idTag");
  6839. memset(sstr ,0, sizeof(sstr) );
  6840. c = 0;
  6841. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6842. {
  6843. sstr[c] = loc[3+strlen("idTag")+c];
  6844. c++;
  6845. }
  6846. sstr[c] = '\0';
  6847. strcpy(idTagstr, sstr);
  6848. //***(4)parentIdTag ****/
  6849. loc = strstr(payload, "parentIdTag");
  6850. memset(sstr ,0, sizeof(sstr) );
  6851. c = 0;
  6852. if(loc == NULL)
  6853. {
  6854. strcpy(parentIdTagstr, "");
  6855. }
  6856. else
  6857. {
  6858. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6859. {
  6860. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6861. c++;
  6862. }
  6863. sstr[c] = '\0';
  6864. strcpy(parentIdTagstr, sstr);
  6865. }
  6866. //***(5)reservationId ****/
  6867. c=0;
  6868. loc = strstr(payload, "reservationId");
  6869. memset(sstr ,0, sizeof(sstr) );
  6870. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6871. {
  6872. sstr[c] = loc[strlen("reservationId")+2+c];
  6873. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6874. c++;
  6875. }
  6876. sstr[c] = '\0';
  6877. reservationIdInt = atoi(sstr);
  6878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6879. if(reservationIdInt == 0)
  6880. {
  6881. //reservationId's value can not be 0
  6882. //strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6883. goto end;
  6884. }
  6885. /*
  6886. enum SYSTEM_STATUS
  6887. {
  6888. SYS_MODE_BOOTING = 0,
  6889. SYS_MODE_IDLE = 1,
  6890. SYS_MODE_AUTHORIZING = 2,
  6891. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6892. SYS_MODE_REASSIGN = 4,
  6893. SYS_MODE_PREPARING = 5,
  6894. SYS_MODE_PREPARE_FOR_EV = 6,
  6895. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6896. SYS_MODE_CHARGING = 8,
  6897. SYS_MODE_TERMINATING = 9,
  6898. SYS_MODE_COMPLETE = 10,
  6899. SYS_MODE_ALARM = 11,
  6900. SYS_MODE_FAULT = 12,
  6901. SYS_MODE_RESERVATION = 13,
  6902. SYS_MODE_BOOKING = 14,
  6903. SYS_MODE_MAINTAIN = 15,
  6904. SYS_MODE_DEBUG = 16,
  6905. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6906. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6907. SYS_MODE_UPDATE = 19
  6908. };
  6909. */
  6910. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6911. {
  6912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6913. goto end;
  6914. }
  6915. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6916. {
  6917. //check Transaction active
  6918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6919. {
  6920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6921. {
  6922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6923. {
  6924. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6925. {
  6926. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6927. {
  6928. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6929. {
  6930. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6932. }
  6933. 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'))
  6934. {
  6935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6936. }
  6937. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  6938. {
  6939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6940. }
  6941. else
  6942. {
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6944. }
  6945. }
  6946. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6947. {
  6948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6949. }
  6950. }
  6951. else
  6952. {
  6953. //replace reservation
  6954. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6956. }
  6957. }
  6958. } // END FOR CHAdeMO_QUANTITY
  6959. for (int index = 0; index < CCS_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6962. {
  6963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6964. {
  6965. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6966. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6967. {
  6968. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6969. {
  6970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6972. }
  6973. 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'))
  6974. {
  6975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6976. }
  6977. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  6978. {
  6979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6980. }
  6981. else
  6982. {
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6984. }
  6985. }
  6986. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6987. {
  6988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6989. }
  6990. }
  6991. else
  6992. {
  6993. //replace reservation
  6994. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6996. }
  6997. }
  6998. } // END FOR CCS_QUANTITY
  6999. for (int index = 0; index < GB_QUANTITY; index++)
  7000. {
  7001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7002. {
  7003. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7004. {
  7005. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7007. {
  7008. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7009. {
  7010. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7012. }
  7013. 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'))
  7014. {
  7015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7016. }
  7017. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7018. {
  7019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7020. }
  7021. else
  7022. {
  7023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7024. }
  7025. }
  7026. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7027. {
  7028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7029. }
  7030. }
  7031. else
  7032. {
  7033. //replace reservation
  7034. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7036. }
  7037. }
  7038. }// END FOR GB_QUANTITY
  7039. }
  7040. else
  7041. {
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7045. {
  7046. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7047. {
  7048. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7049. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7050. {
  7051. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7052. {
  7053. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7055. }
  7056. 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'))
  7057. {
  7058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7059. }
  7060. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7061. {
  7062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7063. }
  7064. else
  7065. {
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7067. }
  7068. }
  7069. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7070. {
  7071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7072. }
  7073. }
  7074. else
  7075. {
  7076. //replace reservation
  7077. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7079. }
  7080. }
  7081. } // END FOR AC_QUANTITY
  7082. }//END FOR AC ELSE
  7083. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7084. }
  7085. else if(connectorIdInt == 0)
  7086. {
  7087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7088. {
  7089. //check Transaction active
  7090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7091. {
  7092. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7093. {
  7094. 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'))
  7095. {
  7096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7097. goto end;
  7098. }
  7099. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7100. {
  7101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7102. goto end;
  7103. }
  7104. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7105. {
  7106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7107. goto end;
  7108. }
  7109. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7110. {
  7111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7112. goto end;
  7113. }
  7114. }
  7115. }// END FOR CHAdeMO_QUANTITY
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7119. {
  7120. 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'))
  7121. {
  7122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7123. }
  7124. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7125. {
  7126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7127. }
  7128. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7129. {
  7130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7131. }
  7132. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7135. }
  7136. }
  7137. } // END FOR CCS_QUANTITY
  7138. for (int index = 0; index < GB_QUANTITY; index++)
  7139. {
  7140. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7141. {
  7142. 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'))
  7143. {
  7144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7145. }
  7146. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7147. {
  7148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7149. }
  7150. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7151. {
  7152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7153. }
  7154. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7155. {
  7156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7157. }
  7158. }
  7159. } // END FOR GB_QUANTITY
  7160. }
  7161. else
  7162. {
  7163. for (int index = 0; index < AC_QUANTITY; index++)
  7164. {
  7165. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7166. {
  7167. 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'))
  7168. {
  7169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7170. goto end;
  7171. }
  7172. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7173. {
  7174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7175. goto end;
  7176. }
  7177. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7178. {
  7179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7180. goto end;
  7181. }
  7182. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7183. {
  7184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7185. goto end;
  7186. }
  7187. }
  7188. }// END FOR AC_QUANTITY
  7189. }
  7190. //The connectorId is 0
  7191. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7193. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7194. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7195. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7196. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7197. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7198. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7199. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7200. result = TRUE;
  7201. return result;
  7202. }
  7203. else
  7204. {
  7205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7206. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7207. }
  7208. if(strcmp(comfirmstr,"Accepted") == 0)
  7209. {
  7210. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7211. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7212. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7213. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7214. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7215. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7216. result = TRUE;
  7217. return result;
  7218. }
  7219. end:
  7220. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7221. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7222. return result;
  7223. }
  7224. int handleResetRequest(char *uuid, char *payload)
  7225. {
  7226. mtrace();
  7227. int result = FAIL;
  7228. char sstr[10]={0};
  7229. char typestr[10]={0};
  7230. char comfirmstr[20]={0};
  7231. int c = 0;
  7232. char *loc;
  7233. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7234. DEBUG_INFO("handleResetRequest ...\n");
  7235. loc = strstr(payload, "type");
  7236. memset(sstr ,0, sizeof(sstr) );
  7237. c = 0;
  7238. while (loc[3+strlen("type")+c] != '\"')
  7239. {
  7240. sstr[c] = loc[3+strlen("type")+c];
  7241. c++;
  7242. }
  7243. sstr[c] = '\0';
  7244. strcpy(typestr,sstr);
  7245. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7246. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7247. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7248. {
  7249. //check Transaction active
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7251. {
  7252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7253. {
  7254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7255. {
  7256. //0: unplug, 1: Plug-in
  7257. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7258. }
  7259. }
  7260. for (int index = 0; index < CCS_QUANTITY; index++)
  7261. {
  7262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7263. {
  7264. //0: unplug, 1: Plug-in
  7265. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7266. }
  7267. }
  7268. for (int index = 0; index < GB_QUANTITY; index++)
  7269. {
  7270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7271. {
  7272. //0: unplug, 1: Plug-in
  7273. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7274. }
  7275. }
  7276. }
  7277. else
  7278. {
  7279. for (int index = 0; index < AC_QUANTITY; index++)
  7280. {
  7281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7282. {
  7283. //0: unplug, 1: Plug-in
  7284. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7285. }
  7286. }
  7287. }// END FOR AC ELSE
  7288. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7289. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7290. result = TRUE;
  7291. return result;
  7292. }
  7293. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7294. {
  7295. //check Transaction active
  7296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7297. {
  7298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7299. {
  7300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7301. {
  7302. //0: unplug, 1: Plug-in
  7303. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7304. }
  7305. }
  7306. for (int index = 0; index < CCS_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7309. {
  7310. //0: unplug, 1: Plug-in
  7311. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7312. }
  7313. }
  7314. for (int index = 0; index < GB_QUANTITY; index++)
  7315. {
  7316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7317. {
  7318. //0: unplug, 1: Plug-in
  7319. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7320. }
  7321. }
  7322. }
  7323. else
  7324. {
  7325. for (int index = 0; index < AC_QUANTITY; index++)
  7326. {
  7327. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7328. {
  7329. //0: unplug, 1: Plug-in
  7330. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7331. }
  7332. }
  7333. }// END FOR AC ELSE
  7334. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7335. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7336. result = TRUE;
  7337. return result;
  7338. }
  7339. else
  7340. {
  7341. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7342. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7343. goto errorend;
  7344. }
  7345. errorend:
  7346. sendResetConfirmation(uuid, comfirmstr);
  7347. return result;
  7348. }
  7349. int handleSendLocalListRequest(char *uuid, char *payload)
  7350. {
  7351. mtrace();
  7352. int result = FAIL;
  7353. int listVersionInt;
  7354. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7355. char listsearch[]="listVersion";
  7356. char updateTypesearch[]="updateType";
  7357. char localAuthorizationListsearch[]="localAuthorizationList";
  7358. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7359. char CardList[500][160]={0};
  7360. char updateTypestr[15]={0};
  7361. char idTagstr[20]={0};
  7362. char parentIdTag[20]={0};
  7363. char expiryDate[30]={0};
  7364. char idTagstatus[16]={0};
  7365. int c = 0;
  7366. int i = 0;
  7367. char *delim1 = "}";
  7368. char * pch;
  7369. char *loc;
  7370. //char *ptr;
  7371. char comfirmstr[20];
  7372. //int n_localAuthorizations = 0;
  7373. int checkState_Faulted = FALSE;
  7374. DEBUG_INFO("handleSendLocalListRequest\n");
  7375. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7376. {
  7377. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7378. goto end;
  7379. }
  7380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7381. {
  7382. //check Charge Point state
  7383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7384. {
  7385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7386. {
  7387. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7388. }
  7389. }
  7390. for (int index = 0; index < CCS_QUANTITY; index++)
  7391. {
  7392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7393. {
  7394. checkState_Faulted = TRUE; //OCPP Status
  7395. }
  7396. }
  7397. for (int index = 0; index < GB_QUANTITY; index++)
  7398. {
  7399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7400. {
  7401. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7402. }
  7403. }
  7404. }
  7405. else
  7406. {
  7407. //check Charge Point state
  7408. for (int index = 0; index < AC_QUANTITY; index++)
  7409. {
  7410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7411. {
  7412. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7413. }
  7414. }
  7415. }// END FOR AC ELSE
  7416. if(checkState_Faulted == TRUE)
  7417. {
  7418. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7419. goto end;
  7420. }
  7421. //listVersion
  7422. c = 0;
  7423. loc = strstr(payload, listsearch);
  7424. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7425. {
  7426. sstr[c] = loc[strlen("listVersion")+2+c];
  7427. c++;
  7428. }
  7429. sstr[c] = '\0';
  7430. listVersionInt = atoi(sstr);
  7431. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7432. //updateType
  7433. loc = strstr(payload, updateTypesearch);
  7434. c = 0;
  7435. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7436. {
  7437. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7438. c++;
  7439. }
  7440. sstr[c] = '\0';
  7441. strcpy(updateTypestr, sstr);
  7442. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7443. //localAuthorizationList
  7444. memset(sstr ,0, sizeof(sstr) );
  7445. loc = strstr(payload, localAuthorizationListsearch);
  7446. if(loc != NULL) // localAuthorizationList is not NULL
  7447. {
  7448. //Check UpdateType
  7449. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7450. {
  7451. //Local list full update
  7452. printf("Local list full update.\n");
  7453. OCPP_getListVerion();
  7454. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7455. {
  7456. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7457. goto end;
  7458. }
  7459. OCPP_cleanLocalList();
  7460. }
  7461. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7462. {
  7463. //Local list different update
  7464. printf("Local list different update.\n");
  7465. OCPP_getListVerion();
  7466. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7467. {
  7468. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7469. goto end;
  7470. }
  7471. }
  7472. else
  7473. {
  7474. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7475. goto end;
  7476. }
  7477. c = 0;
  7478. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7479. {
  7480. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7482. c++;
  7483. }
  7484. sstr[c] = '\0';
  7485. //DEBUG_INFO("sstr=%s\n", sstr);
  7486. //parsing strings to words
  7487. i = 0;
  7488. pch = strtok(sstr,delim1);
  7489. while (pch != NULL)
  7490. {
  7491. strcpy(CardList[i], pch);
  7492. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7493. pch = strtok (NULL, delim1);
  7494. i = i + 1;
  7495. }
  7496. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7497. //local Authorizations List Numbers
  7498. //n_localAuthorizations = i;
  7499. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7500. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7501. c= 0;
  7502. while(c < i) // i is CardList Number
  7503. {
  7504. //Search "IdToken"
  7505. memset(sstr ,0, sizeof(sstr) );
  7506. loc = strstr(CardList[c], "idTag");
  7507. int j = 0;
  7508. while (loc[3+strlen("idTag")+j] != '\"')
  7509. {
  7510. sstr[j] = loc[3+strlen("idTag")+j];
  7511. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7512. j++;
  7513. }
  7514. sstr[j] = '\0';
  7515. strcpy(idTagstr, sstr);
  7516. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7517. //Search "expiryDate"
  7518. memset(sstr ,0, sizeof(sstr) );
  7519. loc = strstr(CardList[c], "expiryDate");
  7520. j = 0;
  7521. if(loc != NULL)
  7522. {
  7523. while (loc[3+strlen("expiryDate")+j] != '\"')
  7524. {
  7525. sstr[j] = loc[3+strlen("expiryDate")+j];
  7526. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7527. j++;
  7528. }
  7529. sstr[j] = '\0';
  7530. strcpy(expiryDate, sstr);
  7531. }
  7532. else
  7533. {
  7534. strcpy(expiryDate, "");
  7535. }
  7536. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7537. //Search "parentIdTag"
  7538. memset(sstr ,0, sizeof(sstr) );
  7539. loc = strstr(CardList[c], "parentIdTag");
  7540. j = 0;
  7541. if(loc != NULL)
  7542. {
  7543. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7544. {
  7545. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7546. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7547. j++;
  7548. }
  7549. sstr[j] = '\0';
  7550. strcpy(parentIdTag, sstr);
  7551. }
  7552. else
  7553. {
  7554. strcpy(parentIdTag, "");
  7555. }
  7556. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7557. //Search "status"
  7558. memset(sstr ,0, sizeof(sstr) );
  7559. loc = strstr(CardList[c], "status");
  7560. j = 0;
  7561. while (loc[3+strlen("status")+j] != '\"')
  7562. {
  7563. sstr[j] = loc[3+strlen("status")+j];
  7564. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7565. j++;
  7566. }
  7567. sstr[j] = '\0';
  7568. strcpy(idTagstatus, sstr);
  7569. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7570. OCPP_getIdTag(idTagstr);
  7571. //OCPP_getIdTag("test"); For Test
  7572. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7573. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7574. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7575. {
  7576. //Local list full update
  7577. DEBUG_INFO("Local list full update.\n");
  7578. // update list
  7579. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7580. //DEBUG_INFO("Local list full update. 1\n");
  7581. //OCPP_get_TableAuthlocalAllData();
  7582. //DEBUG_INFO("Local list full update. 2\n");
  7583. }
  7584. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7585. {
  7586. #if 0
  7587. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7588. {
  7589. //OCPP_deleteIdTag(idTagstr);
  7590. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7591. }
  7592. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7593. {
  7594. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7595. }
  7596. #endif
  7597. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7598. }
  7599. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7600. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7601. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7602. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7603. c++;
  7604. }
  7605. }
  7606. else
  7607. {
  7608. //Check UpdateType
  7609. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7610. {
  7611. //Local list full update
  7612. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7613. OCPP_cleanLocalList();
  7614. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7615. goto end;
  7616. }
  7617. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7618. {
  7619. //Local list different update
  7620. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7621. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7622. goto end;
  7623. }
  7624. }
  7625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7626. end:
  7627. sendSendLocalListConfirmation(uuid, comfirmstr);
  7628. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7629. return result;
  7630. }
  7631. #define MAX 200
  7632. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7633. {
  7634. mtrace();
  7635. int result = FAIL;
  7636. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7637. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7638. char chargingProfilePurposeStr[30]={0};
  7639. char chargingProfileKindStr[16]={0};
  7640. char recurrencyKindStr[10]={0};
  7641. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7642. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7643. int chargingSchedulePeriodCount = 0;
  7644. //int updateflag = FALSE;
  7645. char comfirmstr[20]={0};
  7646. int meet= FALSE;
  7647. char sstr[10]={0};
  7648. int c = 0;
  7649. char *loc;
  7650. FILE *fptr1;//, *fptr2;
  7651. //int lno=0;//, linectr = 0;
  7652. //int modifyflag = FALSE;
  7653. char filename[MAX]={0};
  7654. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7655. //int resultRename=0;
  7656. char rmFileCmd[50]={0};
  7657. char tempchargingProfilePurposeStr[30]={0};
  7658. char word[1600]={0};
  7659. int n_chargingProfile = 0;
  7660. //[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}}}]
  7661. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7662. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7663. //*********************connectorId***************************/
  7664. loc = strstr(payload, "connectorId");
  7665. c = 0;
  7666. memset(sstr ,0, sizeof(sstr) );
  7667. while (loc[strlen("connectorId")+2+c] != ',')
  7668. {
  7669. sstr[c] = loc[strlen("connectorId")+2+c];
  7670. c++;
  7671. }
  7672. sstr[c] = '\0';
  7673. connectorIdInt = atoi(sstr);
  7674. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7675. {
  7676. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7677. }
  7678. else
  7679. {
  7680. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7681. }
  7682. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7683. //*********************chargingProfileId***************************/
  7684. loc = strstr(payload, "chargingProfileId");
  7685. c = 0;
  7686. memset(sstr ,0, sizeof(sstr) );
  7687. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7688. {
  7689. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7690. c++;
  7691. }
  7692. sstr[c] = '\0';
  7693. chargingProfileIdInt = atoi(sstr);
  7694. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7695. {
  7696. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7697. }
  7698. else
  7699. {
  7700. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7701. }
  7702. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7703. //*********************transactionId***************************/
  7704. loc = strstr(payload, "transactionId");
  7705. if(loc != NULL)
  7706. {
  7707. c = 0;
  7708. memset(sstr ,0, sizeof(sstr) );
  7709. while (loc[strlen("transactionId")+2+c] != ',')
  7710. {
  7711. sstr[c] = loc[strlen("transactionId")+2+c];
  7712. c++;
  7713. }
  7714. sstr[c] = '\0';
  7715. transactionIdInt = atoi(sstr);
  7716. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7717. {
  7718. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7719. }
  7720. else
  7721. {
  7722. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7723. }
  7724. }
  7725. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7726. //*********************stackLevel***************************/
  7727. loc = strstr(payload, "stackLevel");
  7728. c = 0;
  7729. memset(sstr ,0, sizeof(sstr) );
  7730. while (loc[strlen("stackLevel")+2+c] != ',')
  7731. {
  7732. sstr[c] = loc[strlen("stackLevel")+2+c];
  7733. c++;
  7734. }
  7735. sstr[c] = '\0';
  7736. stackLevelInt = atoi(sstr);
  7737. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7738. {
  7739. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7740. }
  7741. else
  7742. {
  7743. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7744. }
  7745. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7746. //*********************chargingProfilePurpose***************************/
  7747. loc = strstr(payload, "chargingProfilePurpose");
  7748. c = 0;
  7749. memset(sstr ,0, sizeof(sstr) );
  7750. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7751. {
  7752. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7753. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7754. c++;
  7755. }
  7756. sstr[c] = '\0';
  7757. strcpy(chargingProfilePurposeStr,sstr);
  7758. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7759. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7760. {
  7761. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7762. }
  7763. else
  7764. {
  7765. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7766. }
  7767. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7768. //*********************chargingProfileKind***************************/
  7769. loc = strstr(payload, "chargingProfileKind");
  7770. c = 0;
  7771. memset(sstr ,0, sizeof(sstr) );
  7772. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7773. {
  7774. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7776. c++;
  7777. }
  7778. sstr[c] = '\0';
  7779. strcpy(chargingProfileKindStr,sstr);
  7780. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7781. {
  7782. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7783. }
  7784. else
  7785. {
  7786. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7787. }
  7788. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7789. //*********************recurrencyKind***************************/
  7790. loc = strstr(payload, "recurrencyKind");
  7791. if(loc != NULL)
  7792. {
  7793. c = 0;
  7794. memset(sstr ,0, sizeof(sstr) );
  7795. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7796. {
  7797. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. strcpy(recurrencyKindStr,sstr);
  7803. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7804. {
  7805. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7806. }
  7807. else
  7808. {
  7809. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7810. }
  7811. }
  7812. else
  7813. {
  7814. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7815. {
  7816. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7817. }
  7818. else
  7819. {
  7820. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7821. }
  7822. }
  7823. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7824. //*********************validFrom***************************/
  7825. loc = strstr(payload, "validFrom");
  7826. if(loc != NULL)
  7827. {
  7828. c = 0;
  7829. memset(sstr ,0, sizeof(sstr) );
  7830. while (loc[3+strlen("validFrom")+c] != '\"')
  7831. {
  7832. sstr[c] = loc[3+strlen("validFrom")+c];
  7833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7834. c++;
  7835. }
  7836. sstr[c] = '\0';
  7837. strcpy(validFromStr,sstr);
  7838. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7839. {
  7840. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7841. }
  7842. else
  7843. {
  7844. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7845. }
  7846. }
  7847. else
  7848. {
  7849. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7850. {
  7851. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7852. }
  7853. else
  7854. {
  7855. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7856. }
  7857. }
  7858. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7859. //*********************validTo***************************/
  7860. loc = strstr(payload, "validTo");
  7861. if(loc != NULL)
  7862. {
  7863. c = 0;
  7864. memset(sstr ,0, sizeof(sstr) );
  7865. while (loc[3+strlen("validTo")+c] != '\"')
  7866. {
  7867. sstr[c] = loc[3+strlen("validTo")+c];
  7868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7869. c++;
  7870. }
  7871. sstr[c] = '\0';
  7872. strcpy(validToStr,sstr);
  7873. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7874. {
  7875. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7876. }
  7877. else
  7878. {
  7879. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7880. }
  7881. }
  7882. else
  7883. {
  7884. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7885. {
  7886. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7887. }
  7888. else
  7889. {
  7890. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7891. }
  7892. }
  7893. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7894. //*********************duration***************************/
  7895. loc = strstr(payload, "duration");
  7896. if(loc != NULL)
  7897. {
  7898. c = 0;
  7899. memset(sstr ,0, sizeof(sstr) );
  7900. while (loc[strlen("duration")+2+c] != ',')
  7901. {
  7902. sstr[c] = loc[strlen("duration")+2+c];
  7903. c++;
  7904. }
  7905. sstr[c] = '\0';
  7906. durationInt = atoi(sstr);
  7907. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7908. {
  7909. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7910. }
  7911. else
  7912. {
  7913. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7914. }
  7915. }
  7916. else
  7917. {
  7918. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7919. {
  7920. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7921. }
  7922. else
  7923. {
  7924. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7925. }
  7926. }
  7927. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7928. //*********************startSchedule***************************/
  7929. loc = strstr(payload, "startSchedule");
  7930. if(loc != NULL)
  7931. {
  7932. c = 0;
  7933. memset(sstr ,0, sizeof(sstr) );
  7934. while (loc[3+strlen("startSchedule")+c] != '\"')
  7935. {
  7936. sstr[c] = loc[3+strlen("startSchedule")+c];
  7937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7938. c++;
  7939. }
  7940. sstr[c] = '\0';
  7941. strcpy(startScheduleStr,sstr);
  7942. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7943. {
  7944. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7945. }
  7946. else
  7947. {
  7948. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7949. }
  7950. }
  7951. else
  7952. {
  7953. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7954. {
  7955. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7956. }
  7957. else
  7958. {
  7959. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7960. }
  7961. }
  7962. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7963. //*********************chargingRateUnit***************************/
  7964. loc = strstr(payload, "chargingRateUnit");
  7965. if(loc != NULL)
  7966. {
  7967. c = 0;
  7968. memset(sstr ,0, sizeof(sstr) );
  7969. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7970. {
  7971. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7972. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7973. c++;
  7974. }
  7975. sstr[c] = '\0';
  7976. strcpy(chargingRateUnitStr,sstr);
  7977. #if 0
  7978. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7979. {
  7980. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7981. goto end;
  7982. }
  7983. #endif
  7984. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7985. {
  7986. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7987. }
  7988. else
  7989. {
  7990. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7991. }
  7992. }
  7993. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7994. //****************chargingSchedulePeriod count start*******************/
  7995. int what_len = strlen("startPeriod");
  7996. char tempChargingProfile[1000]={0};
  7997. strcpy(tempChargingProfile,(const char*)payload);
  7998. char *where = tempChargingProfile;
  7999. if (what_len)
  8000. {
  8001. while ((where = strstr(where, "startPeriod"))) {
  8002. where += what_len;
  8003. chargingSchedulePeriodCount++;
  8004. }
  8005. }
  8006. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8007. {
  8008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8009. goto end;
  8010. }
  8011. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8012. //where = payload;
  8013. int templength = 0;
  8014. //int searchstart = 0;
  8015. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8016. {
  8017. //****************startPeriod*******************/
  8018. c=0;
  8019. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8020. memset(sstr ,0, sizeof(sstr) );
  8021. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8022. {
  8023. sstr[c] = loc[strlen("startPeriod")+2+c];
  8024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8025. c++;
  8026. }
  8027. sstr[c] = '\0';
  8028. startPeriodInt[periodNums] = atoi(sstr);
  8029. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8030. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8031. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8032. {
  8033. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8034. }
  8035. else
  8036. {
  8037. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8038. }
  8039. templength = strlen("startPeriod")+2+c;
  8040. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8041. //****************limit*******************/
  8042. c=0;
  8043. loc = strstr(tempChargingProfile + templength, "limit");
  8044. memset(sstr ,0, sizeof(sstr) );
  8045. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8046. {
  8047. sstr[c] = loc[strlen("limit")+2+c];
  8048. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8049. c++;
  8050. }
  8051. sstr[c] = '\0';
  8052. limitflaot[periodNums] = atof(sstr);
  8053. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8054. {
  8055. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8056. }
  8057. else
  8058. {
  8059. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8060. }
  8061. templength = templength + strlen("limit")+2+c;
  8062. //****************numberPhases*******************/
  8063. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8064. if(loc != NULL)
  8065. {
  8066. c=0;
  8067. memset(sstr ,0, sizeof(sstr) );
  8068. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8069. {
  8070. sstr[c] = loc[strlen("numberPhases")+2+c];
  8071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8072. c++;
  8073. }
  8074. sstr[c] = '\0';
  8075. numberPhasesInt[periodNums] = atoi(sstr);
  8076. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8077. {
  8078. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8079. }
  8080. else
  8081. {
  8082. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8083. }
  8084. templength = templength + strlen("numberPhases")+2+c;
  8085. }
  8086. //where = loc;
  8087. }
  8088. //****************chargingSchedulePeriod count end*******************/
  8089. //*********************minChargingRate***************************/
  8090. loc = strstr(payload, "minChargingRate");
  8091. if(loc != NULL)
  8092. {
  8093. c = 0;
  8094. memset(sstr ,0, sizeof(sstr) );
  8095. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8096. {
  8097. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8098. c++;
  8099. }
  8100. sstr[c] = '\0';
  8101. minChargingRateFloat = atof(sstr);
  8102. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8103. {
  8104. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8105. }
  8106. else
  8107. {
  8108. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8109. }
  8110. }
  8111. else
  8112. {
  8113. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8114. {
  8115. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8116. }
  8117. else
  8118. {
  8119. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8120. }
  8121. }
  8122. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8123. {
  8124. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8125. if(connectorIdInt != 0)
  8126. {
  8127. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8128. goto end;
  8129. }
  8130. strcpy(filename, ChargePointMaxProfile_JSON );
  8131. fptr1 = fopen(filename, "r");
  8132. if (!fptr1)
  8133. {
  8134. //file not exist
  8135. DEBUG_INFO("Unable to open the input file!!\n");
  8136. fptr1 = fopen(filename, "w+");
  8137. }
  8138. else
  8139. {
  8140. //Check Charging Profile Count
  8141. while(fscanf(fptr1, "%s", word) != EOF)
  8142. {
  8143. //DEBUG_INFO("word=%s\n",word);
  8144. if(strstr(word, "chargingProfileId")!= NULL)
  8145. {
  8146. //DEBUG_INFO("test chargingProfileId \n");
  8147. n_chargingProfile = n_chargingProfile + 1;
  8148. //DEBUG_INFO("chargingProfileId Found\n");
  8149. }
  8150. }
  8151. }
  8152. fclose(fptr1);
  8153. }
  8154. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8155. {
  8156. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8157. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8158. {
  8159. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8160. goto end;
  8161. }
  8162. memset(filename, 0, sizeof filename);
  8163. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8164. fptr1 = fopen(filename, "r");
  8165. if (!fptr1)
  8166. {
  8167. //file not exist
  8168. //DEBUG_INFO("Unable to open the input file!!\n");
  8169. fptr1 = fopen(filename, "w+");
  8170. }
  8171. else
  8172. {
  8173. //Check Charging Profile Count
  8174. while(fscanf(fptr1, "%s", word) != EOF)
  8175. {
  8176. //DEBUG_INFO("word=%s\n",word);
  8177. if(strstr(word, "chargingProfileId")!= NULL)
  8178. {
  8179. //DEBUG_INFO("test chargingProfileId \n");
  8180. n_chargingProfile = n_chargingProfile + 1;
  8181. //DEBUG_INFO("chargingProfileId Found\n");
  8182. }
  8183. }
  8184. }
  8185. fclose(fptr1);
  8186. }
  8187. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8188. {
  8189. //printf("set chargingProfile 1-4\n");
  8190. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8191. //check Transaction active
  8192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8193. {
  8194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8195. {
  8196. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8197. {
  8198. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8199. {
  8200. meet = TRUE;
  8201. break;
  8202. }
  8203. }
  8204. }
  8205. }
  8206. for (int index = 0; index < CCS_QUANTITY; index++)
  8207. {
  8208. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8209. {
  8210. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8211. {
  8212. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8213. {
  8214. meet = TRUE;
  8215. break;
  8216. }
  8217. }
  8218. }
  8219. }
  8220. for (int index = 0; index < GB_QUANTITY; index++)
  8221. {
  8222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8223. {
  8224. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8225. {
  8226. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8227. {
  8228. meet = TRUE;
  8229. break;
  8230. }
  8231. }
  8232. }
  8233. }
  8234. for (int index = 0; index < AC_QUANTITY; index++)
  8235. {
  8236. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  8237. {
  8238. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8239. {
  8240. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8241. {
  8242. meet = TRUE;
  8243. break;
  8244. }
  8245. }
  8246. }
  8247. }
  8248. if(meet == FALSE)
  8249. {
  8250. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8251. goto end;
  8252. }
  8253. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8254. {
  8255. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8256. goto end;
  8257. }
  8258. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8259. fptr1 = fopen(filename, "r");
  8260. if (!fptr1)
  8261. {
  8262. //file not exist
  8263. DEBUG_INFO("Unable to open the input file!!\n");
  8264. fptr1 = fopen(filename, "w+");
  8265. }
  8266. else
  8267. {
  8268. //Check Charging Profile Count
  8269. while(fscanf(fptr1, "%s", word) != EOF)
  8270. {
  8271. //DEBUG_INFO("word=%s\n",word);
  8272. if(strstr(word, "chargingProfileId")!= NULL)
  8273. {
  8274. //DEBUG_INFO("test chargingProfileId \n");
  8275. n_chargingProfile = n_chargingProfile + 1;
  8276. //DEBUG_INFO("chargingProfileId Found\n");
  8277. }
  8278. }
  8279. }
  8280. fclose(fptr1);
  8281. }
  8282. // Check ChargeProfileMaxStackLevel
  8283. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8284. {
  8285. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8286. goto end;
  8287. }
  8288. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8289. {
  8290. int i = 0;
  8291. char fnametemp[200]={0};
  8292. n_chargingProfile = 0;
  8293. //Check ChargePointMaxProfile.json exit
  8294. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8295. {
  8296. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8297. //Check Charging Profile Count
  8298. while(fscanf(fptr1, "%s", word) != EOF)
  8299. {
  8300. //DEBUG_INFO("word=%s\n",word);
  8301. if(strstr(word, "chargingProfileId")!= NULL)
  8302. {
  8303. //DEBUG_INFO("test chargingProfileId \n");
  8304. n_chargingProfile = n_chargingProfile + 1;
  8305. i = i + 1;
  8306. //DEBUG_INFO("chargingProfileId Found\n");
  8307. }
  8308. memset(word, 0, sizeof word);
  8309. }
  8310. fclose(fptr1);
  8311. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8312. }
  8313. //Check TxDefaultProfile_0.json exit
  8314. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8315. {
  8316. i = 0;
  8317. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8318. //Check Charging Profile Count
  8319. while(fscanf(fptr1, "%s", word) != EOF)
  8320. {
  8321. //DEBUG_INFO("word=%s\n",word);
  8322. if(strstr(word, "chargingProfileId")!= NULL)
  8323. {
  8324. //DEBUG_INFO("test chargingProfileId \n");
  8325. n_chargingProfile = n_chargingProfile + 1;
  8326. i = i + 1;
  8327. //DEBUG_INFO("chargingProfileId Found\n");
  8328. }
  8329. memset(word, 0, sizeof word);
  8330. }
  8331. fclose(fptr1);
  8332. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8333. }
  8334. //Check TxDefaultProfile_%d.json
  8335. for(int j=1; j <= gunTotalNumber; j++)
  8336. {
  8337. memset(fnametemp, 0, sizeof fnametemp);
  8338. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8339. if((access(fnametemp,F_OK))!=-1)
  8340. {
  8341. i = 0;
  8342. fptr1 = fopen(fnametemp, "r");
  8343. //Check Charging Profile Count
  8344. while(fscanf(fptr1, "%s", word) != EOF)
  8345. {
  8346. //DEBUG_INFO("word=%s\n",word);
  8347. if(strstr(word, "chargingProfileId")!= NULL)
  8348. {
  8349. //DEBUG_INFO("test chargingProfileId \n");
  8350. n_chargingProfile = n_chargingProfile + 1;
  8351. i = i + 1;
  8352. //DEBUG_INFO("chargingProfileId Found\n");
  8353. }
  8354. memset(word, 0, sizeof word);
  8355. }
  8356. fclose(fptr1);
  8357. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8358. }
  8359. }
  8360. //Check TxProfile_%d.json
  8361. for(int j=1; j <= gunTotalNumber; j++)
  8362. {
  8363. memset(fnametemp, 0, sizeof fnametemp);
  8364. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%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. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8387. {
  8388. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8389. goto end;
  8390. }
  8391. }
  8392. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8393. //**********************************Write to File********************************************************/
  8394. FILE *infile;
  8395. FILE *outfile;
  8396. // open file for writing
  8397. infile = fopen (filename, "r");
  8398. outfile = fopen (tempfile, "w");
  8399. int d =0;
  8400. d = fgetc(infile);
  8401. //DEBUG_INFO("d:%d\n",d);
  8402. rewind(infile);
  8403. //*检测到文件结束标识返回1,否则返回0。*/
  8404. if(d == EOF)
  8405. {
  8406. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8407. fprintf(outfile,"%s\n",payload);
  8408. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8409. fclose(infile);
  8410. fclose(outfile);
  8411. sprintf(rmFileCmd,"rm -f %s",filename);
  8412. system(rmFileCmd);
  8413. rename(tempfile, filename);
  8414. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8415. //system(rmFileCmd);
  8416. }
  8417. else
  8418. {
  8419. char buf[1000]={0};
  8420. int ChargingProfileAdded = FALSE;
  8421. while (fgets(buf, sizeof(buf), infile) != NULL)
  8422. {
  8423. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8424. //*************************tempconnectorIdInt*********************************/
  8425. loc = strstr(buf, "connectorId");
  8426. c = 0;
  8427. memset(sstr ,0, sizeof(sstr) );
  8428. while (loc[strlen("connectorId")+2+c] != ',')
  8429. {
  8430. sstr[c] = loc[strlen("connectorId")+2+c];
  8431. c++;
  8432. }
  8433. sstr[c] = '\0';
  8434. tempconnectorIdInt = atoi(sstr);
  8435. //*************************tempchargingProfileIdInt*********************************/
  8436. loc = strstr(buf, "chargingProfileId");
  8437. c = 0;
  8438. memset(sstr ,0, sizeof(sstr) );
  8439. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8440. {
  8441. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8442. c++;
  8443. }
  8444. sstr[c] = '\0';
  8445. tempchargingProfileIdInt = atoi(sstr);
  8446. //*************************tempstackLevelInt*********************************/
  8447. loc = strstr(buf, "stackLevel");
  8448. c = 0;
  8449. memset(sstr ,0, sizeof(sstr) );
  8450. while (loc[strlen("stackLevel")+2+c] != ',')
  8451. {
  8452. sstr[c] = loc[strlen("stackLevel")+2+c];
  8453. c++;
  8454. }
  8455. sstr[c] = '\0';
  8456. tempstackLevelInt = atoi(sstr);
  8457. //*************************tempchargingProfilePurposeStr*********************************/
  8458. loc = strstr(payload, "chargingProfilePurpose");
  8459. c = 0;
  8460. memset(sstr ,0, sizeof(sstr) );
  8461. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8462. {
  8463. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8465. c++;
  8466. }
  8467. sstr[c] = '\0';
  8468. strcpy(tempchargingProfilePurposeStr,sstr);
  8469. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8470. {
  8471. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8472. {
  8473. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8474. if(ChargingProfileAdded == FALSE)
  8475. {
  8476. fprintf(outfile,"%s\n",payload);
  8477. ChargingProfileAdded = TRUE;
  8478. }
  8479. }
  8480. else
  8481. {
  8482. if(tempstackLevelInt < stackLevelInt)
  8483. {
  8484. if(ChargingProfileAdded == FALSE)
  8485. {
  8486. fprintf(outfile,"%s\n",payload);
  8487. ChargingProfileAdded = TRUE;
  8488. fprintf(outfile,"%s\n",buf);
  8489. }
  8490. else
  8491. {
  8492. fprintf(outfile,"%s\n",buf);
  8493. }
  8494. }
  8495. else
  8496. {
  8497. if(ChargingProfileAdded == FALSE)
  8498. {
  8499. fprintf(outfile,"%s\n",buf);
  8500. fprintf(outfile,"%s\n",payload);
  8501. ChargingProfileAdded = TRUE;
  8502. }
  8503. else
  8504. {
  8505. fprintf(outfile,"%s\n",buf);
  8506. }
  8507. }
  8508. }
  8509. }
  8510. else
  8511. {
  8512. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8513. {
  8514. if(ChargingProfileAdded == FALSE)
  8515. {
  8516. fprintf(outfile,"%s\n",payload);
  8517. ChargingProfileAdded = TRUE;
  8518. fprintf(outfile,"%s\n",buf);
  8519. }
  8520. else
  8521. {
  8522. fprintf(outfile,"%s\n",buf);
  8523. }
  8524. }
  8525. else if(tempstackLevelInt < stackLevelInt)
  8526. {
  8527. if(ChargingProfileAdded == FALSE)
  8528. {
  8529. fprintf(outfile,"%s\n",payload);
  8530. ChargingProfileAdded = TRUE;
  8531. fprintf(outfile,"%s\n",buf);
  8532. }
  8533. else
  8534. {
  8535. fprintf(outfile,"%s\n",buf);
  8536. }
  8537. }
  8538. else
  8539. {
  8540. if(ChargingProfileAdded == FALSE)
  8541. {
  8542. fprintf(outfile,"%s\n",buf);
  8543. fprintf(outfile,"%s\n",payload);
  8544. ChargingProfileAdded = TRUE;
  8545. }
  8546. else
  8547. {
  8548. fprintf(outfile,"%s\n",buf);
  8549. }
  8550. }
  8551. }
  8552. } // end of while loop
  8553. fclose(infile);
  8554. fclose(outfile);
  8555. sprintf(rmFileCmd,"rm -f %s",filename);
  8556. system(rmFileCmd);
  8557. rename(tempfile, filename);
  8558. result = TRUE;
  8559. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8560. }
  8561. end:
  8562. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8563. return result;
  8564. return result;
  8565. }
  8566. int handleTriggerMessageRequest(char *uuid, char *payload)
  8567. {
  8568. mtrace();
  8569. int result = FAIL;
  8570. int connectorIdIsNULL = FALSE;
  8571. int connectorIdInt =0;
  8572. char sstr[40]={0};
  8573. char requestedMessagestr[40]={0};
  8574. char comfirmstr[20]={0};
  8575. int c = 0;
  8576. char *loc;
  8577. DEBUG_INFO("handleTriggerMessageRequest\n");
  8578. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8579. c = 0;
  8580. loc = strstr(payload, "requestedMessage");
  8581. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8582. {
  8583. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8584. c++;
  8585. }
  8586. sstr[c] = '\0';
  8587. strcpy(requestedMessagestr, sstr);
  8588. c = 0;
  8589. loc = strstr(payload, "connectorId");
  8590. if(loc == NULL)
  8591. {
  8592. connectorIdIsNULL = TRUE;
  8593. }
  8594. else
  8595. {
  8596. memset(sstr ,0, sizeof(sstr) );
  8597. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8598. {
  8599. sstr[c] = loc[strlen("connectorId")+2+c];
  8600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8601. c++;
  8602. }
  8603. sstr[c] = '\0';
  8604. connectorIdInt = atoi(sstr);
  8605. }
  8606. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8607. {
  8608. //connectorIdInt = json_object_get_int(connectorId);
  8609. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8610. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8611. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8612. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8613. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8614. }
  8615. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8616. {
  8617. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8618. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8619. return TRUE;
  8620. }
  8621. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8622. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8623. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8624. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8625. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8626. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8627. {
  8628. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8629. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8630. return TRUE;
  8631. }
  8632. else
  8633. {
  8634. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8635. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8636. }
  8637. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8638. {
  8639. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8640. {
  8641. FirmwareStatusNotificationStatus = 3;
  8642. }
  8643. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8644. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8645. }
  8646. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8647. {
  8648. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8649. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8650. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8651. }
  8652. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8653. {
  8654. sendBootNotificationRequest();
  8655. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8656. }
  8657. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8658. {
  8659. sendHeartbeatRequest(connectorIdInt);
  8660. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8661. }
  8662. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8663. {
  8664. if(connectorIdIsNULL == FALSE)
  8665. {
  8666. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8667. {
  8668. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8669. sendMeterValuesRequest(connectorIdInt -1);
  8670. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8671. }
  8672. }
  8673. else
  8674. {
  8675. for(int idx=0;idx< gunTotalNumber;idx++)
  8676. {
  8677. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8678. sendMeterValuesRequest(idx);
  8679. }
  8680. }
  8681. }
  8682. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8683. {
  8684. if(connectorIdIsNULL == FALSE)
  8685. {
  8686. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8687. {
  8688. sendStatusNotificationRequest(connectorIdInt -1);
  8689. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8690. }
  8691. }
  8692. else
  8693. {
  8694. for(int idx=0;idx< gunTotalNumber;idx++)
  8695. sendStatusNotificationRequest(idx);
  8696. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8697. }
  8698. }
  8699. return result;
  8700. }
  8701. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8702. {
  8703. mtrace();
  8704. int result = FAIL;
  8705. char sstr[6]={0};
  8706. int connectorIdInt =0;
  8707. char comfirmstr[20]={0};
  8708. int c = 0;
  8709. char *loc;
  8710. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8711. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8712. c = 0;
  8713. loc = strstr(payload, "connectorId");
  8714. memset(sstr ,0, sizeof(sstr) );
  8715. while (loc[strlen("connectorId")+2+c] != '}')
  8716. {
  8717. sstr[c] = loc[strlen("connectorId")+2+c];
  8718. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8719. c++;
  8720. }
  8721. sstr[c] = '\0';
  8722. connectorIdInt = atoi(sstr);
  8723. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8724. if(gunTotalNumber == 0)
  8725. {
  8726. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8727. goto end;
  8728. }
  8729. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8730. {
  8731. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8732. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8733. goto end;
  8734. }
  8735. else
  8736. {
  8737. //check Transaction active
  8738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8739. {
  8740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8741. {
  8742. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8743. {
  8744. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8745. }
  8746. }
  8747. for (int index = 0; index < CCS_QUANTITY; index++)
  8748. {
  8749. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8750. {
  8751. //stop Transaction
  8752. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8753. }
  8754. }
  8755. for (int index = 0; index < GB_QUANTITY; index++)
  8756. {
  8757. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8758. {
  8759. //stop Transaction
  8760. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8761. }
  8762. }
  8763. }
  8764. else
  8765. {
  8766. for (int index = 0; index < AC_QUANTITY; index++)
  8767. {
  8768. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8769. {
  8770. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8771. }
  8772. }
  8773. }// END FOR AC ELSE
  8774. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8775. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8776. result = TRUE;
  8777. return result;
  8778. }
  8779. end:
  8780. //json_object_put(obj); --- remove temporally
  8781. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8782. return result;
  8783. }
  8784. static char UpdateFirmwarepayloadData[300]={0};
  8785. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8786. {
  8787. mtrace();
  8788. int result = FAIL;
  8789. pthread_t t;
  8790. sendUpdateFirmwareConfirmation(uuid);
  8791. memset(UpdateFirmwarepayloadData, 0, 300);
  8792. strcpy(UpdateFirmwarepayloadData, payload);
  8793. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8794. ////pthread_join(t, NULL); //
  8795. //pthread_detach(t);
  8796. //sendUpdateFirmwareConfirmation(uuid);
  8797. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8798. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8799. return result;
  8800. }
  8801. void *UpdateFirmwareProcess(void *data)
  8802. {
  8803. pthread_detach(pthread_self());
  8804. mtrace();
  8805. int retriesInt =0, retryIntervalInt=0;
  8806. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8807. int port=0;
  8808. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8809. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8810. //char comfirmstr[20];
  8811. int isSuccess = 0;
  8812. char ftpbuf[200];
  8813. char temp[100];
  8814. char * pch;
  8815. int retriesISNULL=FALSE;
  8816. int retryInterval=FALSE;
  8817. int c = 0;
  8818. //int i = 0;
  8819. char *loc;
  8820. char sstr[300]={ 0 };
  8821. char str[300]={ 0 };
  8822. //char *str = (char*) data; // ? ?輸入資 ?
  8823. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8824. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8825. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8826. //***************location **************/
  8827. loc = strstr(str, "location");
  8828. memset(sstr ,0, sizeof(sstr) );
  8829. c = 0;
  8830. while (loc[3+strlen("location")+c] != '\"')
  8831. {
  8832. sstr[c] = loc[3+strlen("location")+c];
  8833. c++;
  8834. }
  8835. sstr[c] = '\0';
  8836. strcpy(locationstr, sstr);
  8837. //***************retries**************/
  8838. c = 0;
  8839. loc = strstr(str, "retries");
  8840. if(loc == NULL)
  8841. {
  8842. retriesISNULL=TRUE;
  8843. }
  8844. else
  8845. {
  8846. memset(sstr ,0, sizeof(sstr) );
  8847. while (loc[strlen("retries")+2+c] != ',')
  8848. {
  8849. sstr[c] = loc[strlen("retries")+2+c];
  8850. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8851. c++;
  8852. }
  8853. sstr[c] = '\0';
  8854. }
  8855. if(retriesISNULL == FALSE)
  8856. {
  8857. retriesInt = atoi(sstr);
  8858. }
  8859. //***************retrieveDate **************/
  8860. loc = strstr(str, "retrieveDate");
  8861. memset(sstr ,0, sizeof(sstr) );
  8862. c = 0;
  8863. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8864. {
  8865. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8866. c++;
  8867. }
  8868. sstr[c] = '\0';
  8869. strcpy(retrieveDatestr, sstr);
  8870. //***************retryInterval **************/
  8871. c = 0;
  8872. loc = strstr(str, "retryInterval");
  8873. memset(sstr ,0, sizeof(sstr) );
  8874. if(loc == NULL)
  8875. {
  8876. retryInterval=TRUE;
  8877. }
  8878. else
  8879. {
  8880. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8881. {
  8882. sstr[c] = loc[strlen("retryInterval")+2+c];
  8883. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8884. c++;
  8885. }
  8886. sstr[c] = '\0';
  8887. }
  8888. if(retryInterval==FALSE)
  8889. {
  8890. retryIntervalInt = atoi(sstr);
  8891. }
  8892. memset(ftppath, 0, sizeof(ftppath));
  8893. memset(path, 0, sizeof(path));
  8894. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8895. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8896. if(strncmp(locationstr,"http", 4) == 0)
  8897. {
  8898. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8899. protocol, host, path);
  8900. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8901. // protocol, user, password, host, path);
  8902. sprintf(ftppath,"/%s", path);
  8903. //DEBUG_INFO("protocol =%s\n",protocol);
  8904. //DEBUG_INFO("host =%s\n",host);
  8905. //DEBUG_INFO("path =%s\n",path);
  8906. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8907. int ftppathlen=strlen(ftppath);
  8908. int i=1;
  8909. char filenametemp[50];
  8910. while(i < ftppathlen)
  8911. {
  8912. int len=ftppathlen-i;
  8913. if(ftppath[len]== 47) // '/' ascll code: 47
  8914. {
  8915. DEBUG_INFO("compare '/' all right\n");
  8916. break;
  8917. }
  8918. i=i+1;
  8919. }
  8920. memset(filenametemp, 0, sizeof(filenametemp));
  8921. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8922. filenametemp[i+1] = 0;
  8923. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8924. do{
  8925. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8926. sleep(retryIntervalInt);
  8927. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8928. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8929. if(!isSuccess)
  8930. {
  8931. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8932. }
  8933. else
  8934. {
  8935. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8936. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8937. //isUpdateRequest = TRUE;
  8938. }
  8939. }
  8940. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8941. {
  8942. memset(ftpbuf, 0, sizeof(ftpbuf));
  8943. memset(temp, 0, sizeof(temp));
  8944. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8945. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8946. int ftppathlen=strlen(ftpbuf);
  8947. int i=1;
  8948. char filenametemp[50];
  8949. while(i < ftppathlen)
  8950. {
  8951. int len=ftppathlen-i;
  8952. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8953. {
  8954. DEBUG_INFO(" compare '/' all right\n");
  8955. break;
  8956. }
  8957. i=i+1;
  8958. }
  8959. memset(filenametemp, 0, sizeof(filenametemp));
  8960. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8961. filenametemp[i+1] = 0;
  8962. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8963. pch=strchr(temp,'@');
  8964. if(pch==NULL)
  8965. {
  8966. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8967. protocol, host, &port, path);
  8968. strcpy(user,"anonymous");
  8969. strcpy(password,"");
  8970. }
  8971. else
  8972. {
  8973. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8974. protocol, user, password, host, &port, path);
  8975. }
  8976. sscanf(host,"%[^/]%s",host1, path1);
  8977. sprintf(ftppath,"%s", path1);
  8978. //DEBUG_INFO("protocol =%s\n",protocol);
  8979. //DEBUG_INFO("user =%s\n",user);
  8980. //DEBUG_INFO("password =%s\n",password);
  8981. //DEBUG_INFO("host1 =%s\n",host1);
  8982. //DEBUG_INFO("port =%d\n",port);
  8983. //DEBUG_INFO("path1 =%s\n",path1);
  8984. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8985. //ftpFile(host, user, password, port, ftppath, fname);
  8986. //download firmware pthred
  8987. if(port == 0)
  8988. {
  8989. port = 21;
  8990. }
  8991. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8992. do{
  8993. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8994. sleep(retryIntervalInt);
  8995. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8996. if(!isSuccess)
  8997. {
  8998. //BulldogUtil.sleepMs(interval*1000);
  8999. DEBUG_INFO("Update firmware request and download file fail.\n");
  9000. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9001. }
  9002. else
  9003. {
  9004. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9005. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9006. //isUpdateRequest = TRUE;
  9007. }
  9008. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9009. }
  9010. else
  9011. {
  9012. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9013. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9014. }
  9015. pthread_exit(NULL);
  9016. }
  9017. //==========================================
  9018. // Handle server response routine
  9019. //==========================================
  9020. void handleAuthorizeResponse(char *payload, int gun_index)
  9021. {
  9022. mtrace();
  9023. char expiryDatestr[30]={0};
  9024. char parentIdTagstr[20]={0};
  9025. char statusstr[20]={0};
  9026. char expiryDatestrtemp[30]={0};
  9027. char parentIdTagstrtemp[20]={0};
  9028. char IdTagstrtemp[20]={0};
  9029. char statusstrtemp[20]={0};
  9030. int expiryDateISNULL=FALSE;
  9031. int parentIdTagISNULL=FALSE;
  9032. char sstr[160]={ 0 };
  9033. char* filename = AuthorizationCache_JSON;
  9034. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9035. int c = 0;
  9036. char *loc;
  9037. int resultRename=0;
  9038. int responseIdTagInfoAsZero= 0;
  9039. char rmFileCmd[50]={0};
  9040. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9041. //***********expiryDate*************/
  9042. loc = strstr(payload, "expiryDate");
  9043. memset(sstr ,0, sizeof(sstr) );
  9044. c = 0;
  9045. if(loc == NULL)
  9046. {
  9047. expiryDateISNULL = TRUE;
  9048. }
  9049. else
  9050. {
  9051. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9052. {
  9053. sstr[c] = loc[3+strlen("expiryDate")+c];
  9054. c++;
  9055. }
  9056. sstr[c] = '\0';
  9057. strcpy(expiryDatestr, sstr);
  9058. }
  9059. //***********parentIdTag*************/
  9060. loc = strstr(payload, "parentIdTag");
  9061. memset(sstr ,0, sizeof(sstr) );
  9062. c = 0;
  9063. if(loc == NULL)
  9064. {
  9065. parentIdTagISNULL = TRUE;
  9066. }
  9067. else
  9068. {
  9069. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9070. {
  9071. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9072. c++;
  9073. }
  9074. sstr[c] = '\0';
  9075. strcpy(parentIdTagstr, sstr);
  9076. }
  9077. //***********status*************/
  9078. loc = strstr(payload, "status");
  9079. memset(sstr ,0, sizeof(sstr) );
  9080. c = 0;
  9081. while (loc[3+strlen("status")+c] != '\"')
  9082. {
  9083. sstr[c] = loc[3+strlen("status")+c];
  9084. c++;
  9085. }
  9086. sstr[c] = '\0';
  9087. strcpy(statusstr, sstr);
  9088. if(expiryDateISNULL == FALSE)
  9089. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9090. if(parentIdTagISNULL == FALSE)
  9091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9092. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9093. //Update idTag information to authorization cache if supproted
  9094. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9095. {
  9096. if((access(filename,F_OK))!=-1)
  9097. {
  9098. printf("AuthorizationCache exist.\n");
  9099. }
  9100. else
  9101. {
  9102. printf("AuthorizationCache not exist\n");
  9103. FILE *log = fopen(filename, "w+");
  9104. if(log == NULL)
  9105. {
  9106. printf("log is NULL\n");
  9107. goto out;
  9108. }
  9109. else
  9110. {
  9111. fclose(log);
  9112. }
  9113. }
  9114. FILE *infile;
  9115. FILE *outfile;
  9116. // open file for writing
  9117. infile = fopen (filename, "r");
  9118. outfile = fopen (tempfile, "w");
  9119. //*检测到文件结束标识返回1,否则返回0。*/
  9120. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9121. int c;
  9122. c = fgetc(infile);
  9123. //DEBUG_INFO("c:%d\n",c);
  9124. rewind(infile);
  9125. if(c == EOF)
  9126. {
  9127. DEBUG_INFO("Orignal File is NULL\n");
  9128. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9129. {
  9130. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9131. }
  9132. else
  9133. {
  9134. strcpy(expiryDatestrtemp, "");
  9135. }
  9136. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9137. {
  9138. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9139. }
  9140. else
  9141. {
  9142. //write Authorize IdTag
  9143. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9144. }
  9145. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9146. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9147. fclose(infile);
  9148. fclose(outfile);
  9149. sprintf(rmFileCmd,"rm -f %s",filename);
  9150. system(rmFileCmd);
  9151. resultRename = rename(tempfile, filename);
  9152. if(resultRename == 0)
  9153. {
  9154. printf("File renamed successfully");
  9155. }
  9156. else
  9157. {
  9158. printf("Error: unable to rename the file");
  9159. }
  9160. }
  9161. else
  9162. {
  9163. char buf[160]={0};
  9164. while (fgets(buf, sizeof(buf), infile) != NULL)
  9165. {
  9166. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9167. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9168. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9169. memset(statusstr, 0, sizeof(statusstrtemp));
  9170. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9171. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9172. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9173. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9174. //------------------IdTag-----------------------
  9175. loc = strstr(buf, "idTag");
  9176. memset(sstr ,0, sizeof(sstr) );
  9177. c = 0;
  9178. while (loc[3+strlen("idTag")+c] != '\"')
  9179. {
  9180. sstr[c] = loc[3+strlen("idTag")+c];
  9181. c++;
  9182. }
  9183. sstr[c] = '\0';
  9184. strcpy(IdTagstrtemp,sstr);
  9185. //*********************expiryDate***************/
  9186. loc = strstr(buf, "expiryDate");
  9187. memset(sstr ,0, sizeof(sstr) );
  9188. c = 0;
  9189. while (loc[3+strlen("expiryDate")+c] != '\"')
  9190. {
  9191. sstr[c] = loc[3+strlen("expiryDate")+c];
  9192. c++;
  9193. }
  9194. sstr[c] = '\0';
  9195. strcpy(expiryDatestr,sstr);
  9196. //*********************parentIdTag***************/
  9197. loc = strstr(buf, "parentIdTag");
  9198. memset(sstr ,0, sizeof(sstr) );
  9199. c = 0;
  9200. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9201. {
  9202. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9203. c++;
  9204. }
  9205. sstr[c] = '\0';
  9206. strcpy(parentIdTagstr,sstr);
  9207. //*********************status***************/
  9208. loc = strstr(buf, "status");
  9209. memset(sstr ,0, sizeof(sstr) );
  9210. c = 0;
  9211. while (loc[3+strlen("status")+c] != '\"')
  9212. {
  9213. sstr[c] = loc[3+strlen("status")+c];
  9214. c++;
  9215. }
  9216. sstr[c] = '\0';
  9217. strcpy(statusstr,sstr);
  9218. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9219. {
  9220. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9221. responseIdTagInfoAsZero = 1;
  9222. }
  9223. else
  9224. {
  9225. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9226. }
  9227. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9228. {
  9229. //modify item
  9230. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9231. {
  9232. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9233. }
  9234. else
  9235. {
  9236. strcpy(expiryDatestrtemp, "");
  9237. }
  9238. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9239. {
  9240. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9241. }
  9242. else
  9243. {
  9244. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9245. }
  9246. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9247. }
  9248. else
  9249. {
  9250. //wrie original item
  9251. strcpy(expiryDatestrtemp, expiryDatestr);
  9252. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9253. strcpy(statusstrtemp, statusstr);
  9254. }
  9255. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9256. }
  9257. fclose(infile);
  9258. fclose(outfile);
  9259. sprintf(rmFileCmd,"rm -f %s",filename);
  9260. system(rmFileCmd);
  9261. resultRename = rename(tempfile, filename);
  9262. if(resultRename == 0)
  9263. {
  9264. DEBUG_INFO("File renamed successfully");
  9265. }
  9266. else
  9267. {
  9268. DEBUG_INFO("Error: unable to rename the file");
  9269. }
  9270. }
  9271. }
  9272. out:
  9273. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9274. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9275. authorizeRetryTimes = 0;
  9276. }
  9277. char * strtrimc( char * s )
  9278. {
  9279. char * p1 = s;
  9280. char * p2 = s;
  9281. while(*p1 != '\0')
  9282. {
  9283. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9284. {
  9285. if(*p1 != ',')
  9286. {
  9287. p1 ++;
  9288. }
  9289. else
  9290. {
  9291. break;
  9292. }
  9293. }
  9294. if(*p1 != ',')
  9295. {
  9296. * p2 ++ = *p1 ++;
  9297. //printf("p2=%s\n",p2);
  9298. }
  9299. else
  9300. {
  9301. break;
  9302. }
  9303. }
  9304. *p2 = '\0';
  9305. return (s);
  9306. }
  9307. void handleBootNotificationResponse(char *payload, int gun_index)
  9308. {
  9309. mtrace();
  9310. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9311. char statusStr[12]={0};
  9312. char currentTimeStr[30]={0};
  9313. char *loc;
  9314. int intervalInt = 0;
  9315. int c = 0;
  9316. //double diff_t;
  9317. struct tm tp;
  9318. char buf[28]={0};
  9319. char timebuf[50]={0};
  9320. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9321. //*** interval ****/
  9322. c = 0;
  9323. loc = strstr(payload, "interval");
  9324. //printf("loc=%s\n",loc);
  9325. memset(sstr ,0, sizeof(sstr) );
  9326. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9327. {
  9328. sstr[c] = loc[strlen("interval")+2+c];
  9329. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9330. c++;
  9331. }
  9332. sstr[c] = '\0';
  9333. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9334. intervalInt = atoi(sstr);
  9335. //***status ****/
  9336. loc = strstr(payload, "status");
  9337. memset(sstr ,0, sizeof(sstr) );
  9338. c = 0;
  9339. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9340. {
  9341. sstr[c] = loc[3+strlen("status")+c];
  9342. c++;
  9343. }
  9344. sstr[c] = '\0';
  9345. strcpy(statusStr, sstr);
  9346. //***currentTime ****/
  9347. loc = strstr(payload, "currentTime");
  9348. //printf("loc=%s\n",loc);
  9349. memset(sstr ,0, sizeof(sstr) );
  9350. c = 0;
  9351. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9352. {
  9353. sstr[c] = loc[3+strlen("currentTime")+c];
  9354. c++;
  9355. }
  9356. sstr[c] = '\0';
  9357. strcpy(currentTimeStr, sstr);
  9358. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9359. HeartBeatWaitTime = BootNotificationInterval;
  9360. clientTime.Heartbeat=time((time_t*)NULL);
  9361. //write back to ShmOCPP16Data->BootNotification
  9362. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9363. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9364. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9365. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9366. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9367. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9368. {
  9369. server_sign = TRUE;
  9370. server_pending =FALSE;
  9371. }
  9372. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9373. {
  9374. server_pending = TRUE;
  9375. }
  9376. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9377. tp.tm_isdst = -1;
  9378. //time_t utc = mktime(&tp);
  9379. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9380. memset(timebuf, 0, sizeof timebuf);
  9381. sprintf(timebuf,"date -s '%s'",buf);
  9382. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9383. system(timebuf);
  9384. //==============================================
  9385. // RTC sync
  9386. //==============================================
  9387. system("/sbin/hwclock -w --systohc");
  9388. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9389. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9390. }
  9391. void handleDataTransferResponse(char *payload, int gun_index)
  9392. {
  9393. char sstr[160]={0};//sstr[200]={ 0 };
  9394. int c = 0;
  9395. char *loc;
  9396. DEBUG_INFO("handleDataTransferResponse ...\n");
  9397. loc = strstr(payload, "status");
  9398. printf("loc=%s\n",loc);
  9399. c = 0;
  9400. while (loc[3+strlen("status")+c] != '\"')
  9401. {
  9402. sstr[c] = loc[3+strlen("status")+c];
  9403. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9404. c++;
  9405. }
  9406. sstr[c] = '\0';
  9407. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9408. }
  9409. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9410. {
  9411. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9412. //struct json_object *obj;
  9413. // obj = json_tokener_parse(payload);
  9414. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9415. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9416. //No fields are defined.
  9417. }
  9418. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9419. {
  9420. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9421. //struct json_object *obj;
  9422. // obj = json_tokener_parse(payload);
  9423. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9424. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9425. //No fields are defined.
  9426. }
  9427. void handleHeartbeatResponse(char *payload, int gun_index)
  9428. {
  9429. mtrace();
  9430. //double diff_t;
  9431. struct tm tp;
  9432. char buf[28]={0};
  9433. char timebuf[50]={0};
  9434. char sstr[30]={ 0 };
  9435. int c = 0;
  9436. char *loc;
  9437. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9438. c = 0;
  9439. loc = strstr(payload, "currentTime");
  9440. memset(sstr ,0, sizeof(sstr) );
  9441. while (loc[3+strlen("currentTime")+c] != '\"')
  9442. {
  9443. sstr[c] = loc[3+strlen("currentTime")+c];
  9444. c++;
  9445. }
  9446. sstr[c] = '\0';
  9447. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9448. // #ifdef SystemLogMessage
  9449. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9450. // #endif
  9451. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9452. tp.tm_isdst = -1;
  9453. //time_t utc = mktime(&tp);
  9454. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9455. memset(timebuf, 0, sizeof timebuf);
  9456. sprintf(timebuf,"date -s '%s'",buf);
  9457. system(timebuf);
  9458. //==============================================
  9459. // RTC sync
  9460. //==============================================
  9461. system("/sbin/hwclock -w --systohc");
  9462. if(FirstHeartBeat == 0)
  9463. {
  9464. FirstHeartBeat = 1;
  9465. }
  9466. HeartBeatWithNOResponse = 0;
  9467. //===============================================
  9468. //Print Out HeartBeat log
  9469. //===============================================
  9470. {
  9471. double diff_t;
  9472. struct tm tp,tp1;
  9473. // BootNotification Receive Time
  9474. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9475. tp.tm_isdst = -1;
  9476. time_t BootNotificationReceiveTime = mktime(&tp);
  9477. //HeartBeat Receive Time
  9478. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9479. tp1.tm_isdst = -1;
  9480. time_t HeartBeatReceiveTime = mktime(&tp1);
  9481. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9482. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9483. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9484. {
  9485. HeartBeatCountPerHour = (int)diff_t / 3600;
  9486. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9487. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9488. }
  9489. }
  9490. }
  9491. void handleMeterValuesResponse(char *payload, int gun_index)
  9492. {
  9493. mtrace();
  9494. //struct json_object *obj;
  9495. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9496. //No fields are defined.
  9497. }
  9498. void handleStartTransactionResponse(char *payload, int gun_index)
  9499. {
  9500. mtrace();
  9501. char sstr[28]={ 0 };
  9502. int c = 0;
  9503. char *loc;
  9504. //int transactionIdInt = 0;
  9505. FILE *outfile;
  9506. char data[100]={0};
  9507. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9508. DEBUG_INFO("handleStartTransactionResponse\n");
  9509. //****************expiryDate********************/
  9510. loc = strstr(payload, "expiryDate");
  9511. if(loc == NULL)
  9512. {
  9513. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9514. }
  9515. else
  9516. {
  9517. c = 0;
  9518. memset(sstr ,0, sizeof(sstr) );
  9519. while (loc[3+strlen("expiryDate")+c] != '\"')
  9520. {
  9521. sstr[c] = loc[3+strlen("expiryDate")+c];
  9522. c++;
  9523. }
  9524. sstr[c] = '\0';
  9525. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9526. }
  9527. //****************parentIdTag********************/
  9528. loc = strstr(payload, "parentIdTag");
  9529. if(loc == NULL)
  9530. {
  9531. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9532. }
  9533. else
  9534. {
  9535. c = 0;
  9536. memset(sstr ,0, sizeof(sstr) );
  9537. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9538. {
  9539. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9540. c++;
  9541. }
  9542. sstr[c] = '\0';
  9543. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9544. }
  9545. //****************status********************/
  9546. loc = strstr(payload, "status");
  9547. if(loc == NULL)
  9548. {
  9549. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9550. }
  9551. else
  9552. {
  9553. c = 0;
  9554. memset(sstr ,0, sizeof(sstr) );
  9555. while (loc[3+strlen("status")+c] != '\"')
  9556. {
  9557. sstr[c] = loc[3+strlen("status")+c];
  9558. c++;
  9559. }
  9560. sstr[c] = '\0';
  9561. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9562. }
  9563. //****************transactionId********************/
  9564. c=0;
  9565. loc = strstr(payload, "transactionId");
  9566. memset(sstr ,0, sizeof(sstr) );
  9567. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9568. {
  9569. sstr[c] = loc[strlen("transactionId")+2+c];
  9570. c++;
  9571. }
  9572. sstr[c] = '\0';
  9573. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9574. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9575. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9576. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9577. //-----------Start : write to the Queue TransactionId file -----------------//
  9578. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9579. {
  9580. //DEBUG_INFO("QueueTransactionId exist.\n");
  9581. }
  9582. else
  9583. {
  9584. //DEBUG_INFO("QueueTransactionId not exist\n");
  9585. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9586. if(log == NULL)
  9587. {
  9588. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9589. return ;
  9590. }
  9591. else
  9592. {
  9593. fclose(log);
  9594. }
  9595. }
  9596. // open file for writing
  9597. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9598. //DEBUG_INFO("data=%s\n",data);
  9599. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9600. fputs(data, outfile);
  9601. //fputs("\n", outfile);
  9602. fclose (outfile);
  9603. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9604. //TransactionId[gun_index] = transactionIdInt;
  9605. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9606. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9607. #ifdef SystemLogMessage
  9608. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9609. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9610. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9611. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9612. #endif
  9613. }
  9614. void handleStatusNotificationResponse(char *payload, int gun_index)
  9615. {
  9616. mtrace();
  9617. printf("handleStatusNotificationResponse\n");
  9618. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9619. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9620. }
  9621. void handleStopTransactionnResponse(char *payload, int gun_index)
  9622. {
  9623. mtrace();
  9624. char sstr[30]={ 0 };
  9625. int c = 0;
  9626. char *loc;
  9627. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9628. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9629. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9630. loc = strstr(payload, "idTagInfo");
  9631. //***********************idTagInfo************************/
  9632. if(loc != NULL)
  9633. {
  9634. //***********************expiryDate************************/
  9635. loc = strstr(payload, "expiryDate");
  9636. if(loc != NULL)
  9637. {
  9638. memset(sstr ,0, sizeof(sstr) );
  9639. c = 0;
  9640. while (loc[3+strlen("expiryDate")+c] != '\"')
  9641. {
  9642. sstr[c] = loc[3+strlen("expiryDate")+c];
  9643. c++;
  9644. }
  9645. sstr[c] = '\0';
  9646. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9647. }
  9648. //***********************parentIdTag************************/
  9649. loc = strstr(payload, "parentIdTag");
  9650. if(loc != NULL)
  9651. {
  9652. memset(sstr ,0, sizeof(sstr) );
  9653. c = 0;
  9654. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9655. {
  9656. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9657. c++;
  9658. }
  9659. sstr[c] = '\0';
  9660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9661. }
  9662. //***********************status************************/
  9663. loc = strstr(payload, "status");
  9664. memset(sstr ,0, sizeof(sstr) );
  9665. c = 0;
  9666. while (loc[3+strlen("status")+c] != '\"')
  9667. {
  9668. sstr[c] = loc[3+strlen("status")+c];
  9669. c++;
  9670. }
  9671. sstr[c] = '\0';
  9672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9673. }
  9674. #ifdef SystemLogMessage
  9675. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9676. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9677. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9678. #endif
  9679. }
  9680. //==========================================
  9681. // Handle Error routine
  9682. //==========================================
  9683. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9684. {
  9685. mtrace();
  9686. #ifdef SystemLogMessage
  9687. DEBUG_INFO("errorCode: %s\n", errorCode);
  9688. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9689. DEBUG_INFO("errorDetails: %s\n", payload);
  9690. #endif
  9691. }
  9692. //===============================================
  9693. // Common routine
  9694. //===============================================
  9695. int initialConfigurationTable(void)
  9696. {
  9697. //clock_t start_t, end_t, total_t;
  9698. FILE *fp;
  9699. FILE *outfile;
  9700. char str[200]={0};
  9701. char sstr[100]={0};
  9702. int c = 0;
  9703. char *loc;
  9704. printf("initialConfigurationTable \n");
  9705. //start_t = clock();
  9706. //printf("Starting of the program, start_t = %ld\n", start_t);
  9707. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9708. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9709. {
  9710. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9711. if(outfile == NULL) {
  9712. DEBUG_INFO("Error opening file");
  9713. return FALSE;
  9714. }
  9715. /*Core Profile*/
  9716. //AllowOfflineTxForUnknownId
  9717. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9718. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  9722. //AuthorizationCacheEnabled
  9723. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9727. //AuthorizeRemoteTxRequests
  9728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9732. //BlinkRepeat
  9733. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9737. //ClockAlignedDataInterval
  9738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9742. //ConnectionTimeOut
  9743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9747. //GetConfigurationMaxKeys
  9748. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9752. // HeartbeatInterval
  9753. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9757. // LightIntensity
  9758. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9762. // LocalAuthorizeOffline
  9763. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9767. // LocalPreAuthorize
  9768. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9772. // MaxEnergyOnInvalidId
  9773. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9776. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9778. // MeterValuesAlignedData
  9779. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9783. // MeterValuesAlignedDataMaxLength
  9784. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9788. // MeterValuesSampledData
  9789. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9793. // MeterValuesSampledDataMaxLength
  9794. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9798. // MeterValueSampleInterval
  9799. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9803. // MinimumStatusDuration
  9804. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9807. server_cycle_Status = 120; //StatusNotification cycle
  9808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9809. // NumberOfConnectors
  9810. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9813. {
  9814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9815. }
  9816. else
  9817. {
  9818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9819. }
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9821. // ResetRetries
  9822. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9826. // ConnectorPhaseRotation
  9827. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9831. // ConnectorPhaseRotationMaxLength
  9832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9836. // StopTransactionOnEVSideDisconnect
  9837. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9841. // StopTransactionOnInvalidId
  9842. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9846. // StopTxnAlignedData
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  9851. // StopTxnAlignedDataMaxLength
  9852. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9856. // StopTxnSampledData
  9857. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9861. // StopTxnSampledDataMaxLength
  9862. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9865. {
  9866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9867. }
  9868. else
  9869. {
  9870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9871. }
  9872. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9874. // SupportedFeatureProfiles
  9875. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9879. // SupportedFeatureProfilesMaxLength
  9880. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9884. // TransactionMessageAttempts
  9885. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9888. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9890. // TransactionMessageRetryInterval
  9891. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9894. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9896. // UnlockConnectorOnEVSideDisconnect
  9897. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9901. // WebSocketPingInterval
  9902. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9906. //* Local Auth List Management Profile*/
  9907. #if 0
  9908. //For OCTT Test Case
  9909. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9912. #endif
  9913. #if 1
  9914. //LocalAuthListEnabled
  9915. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9919. #endif
  9920. //LocalAuthListMaxLength
  9921. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9925. //SendLocalListMaxLength
  9926. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9930. //ReserveConnectorZeroSupported
  9931. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9935. //* Smart Charging Profile */
  9936. //ChargeProfileMaxStackLevel
  9937. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9941. // ChargingScheduleAllowedChargingRateUnit
  9942. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9946. // ChargingScheduleMaxPeriods
  9947. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9951. // ConnectorSwitch3to1PhaseSupported
  9952. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9956. // MaxChargingProfilesInstalled
  9957. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9961. fclose(outfile);
  9962. }
  9963. else
  9964. {
  9965. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9966. char keystr[60]={0};
  9967. char readonlystr[10]={0};
  9968. char valuestr[100]={0};
  9969. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9970. if(fp == NULL) {
  9971. DEBUG_INFO("Error opening file");
  9972. return FALSE;
  9973. }
  9974. while( fgets (str, sizeof(str), fp)!=NULL )
  9975. {
  9976. //DEBUG_INFO("Get Configuration \n");
  9977. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9978. //*************************key*********************************/
  9979. loc = strstr(str, "key");
  9980. c = 0;
  9981. memset(sstr ,0, sizeof(sstr) );
  9982. while (loc[strlen("key")+3+c] != '\"')
  9983. {
  9984. sstr[c] = loc[strlen("key")+3+c];
  9985. c++;
  9986. }
  9987. sstr[c] = '\0';
  9988. strcpy(keystr,sstr);
  9989. //*************************readonly*********************************/
  9990. loc = strstr(str, "readonly");
  9991. c = 0;
  9992. memset(sstr ,0, sizeof(sstr) );
  9993. while (loc[strlen("readonly")+2+c] != ',')
  9994. {
  9995. sstr[c] = loc[strlen("readonly")+2+c];
  9996. c++;
  9997. }
  9998. sstr[c] = '\0';
  9999. strcpy(readonlystr,sstr);
  10000. //*************************value*********************************/
  10001. loc = strstr(str, "value");
  10002. c = 0;
  10003. memset(sstr ,0, sizeof(sstr) );
  10004. while (loc[strlen("value")+3+c] != '\"')
  10005. {
  10006. sstr[c] = loc[strlen("value")+3+c];
  10007. c++;
  10008. }
  10009. sstr[c] = '\0';
  10010. strcpy(valuestr,sstr);
  10011. // DEBUG_INFO("keystr=%s\n",keystr);
  10012. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10013. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10014. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10015. {
  10016. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10017. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10019. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10020. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10021. }
  10022. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10023. {
  10024. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10025. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10027. }
  10028. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10029. {
  10030. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10032. }
  10033. if(strcmp(keystr, "BlinkRepeat") == 0)
  10034. {
  10035. //Charger.BlinkRepeat = Integer.parseInt(value);
  10036. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10038. }
  10039. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10040. {
  10041. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10043. }
  10044. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10045. {
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10048. }
  10049. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10050. {
  10051. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10053. }
  10054. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10055. {
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10058. HeartBeatWaitTime = atoi(valuestr);
  10059. }
  10060. if(strcmp(keystr, "LightIntensity") == 0)
  10061. {
  10062. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10064. }
  10065. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10066. {
  10067. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10069. }
  10070. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10071. {
  10072. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10074. }
  10075. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10076. {
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10079. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10080. }
  10081. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10082. {
  10083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10085. }
  10086. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10087. {
  10088. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10090. }
  10091. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10092. {
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10095. }
  10096. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10097. {
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10100. }
  10101. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10102. {
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10105. }
  10106. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10107. {
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10110. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10111. }
  10112. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10113. {
  10114. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10116. }
  10117. if(strcmp(keystr, "ResetRetries") == 0)
  10118. {
  10119. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10121. }
  10122. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10123. {
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10126. }
  10127. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10128. {
  10129. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10131. }
  10132. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10133. {
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10136. }
  10137. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10138. {
  10139. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10141. }
  10142. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10143. {
  10144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10146. }
  10147. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10148. {
  10149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10151. }
  10152. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10153. {
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10156. }
  10157. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10158. {
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10161. }
  10162. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10163. {
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10166. }
  10167. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10168. {
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10171. }
  10172. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10173. {
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10176. TransactionMessageAttemptsValue = atoi(valuestr);
  10177. }
  10178. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10179. {
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10182. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10183. }
  10184. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10185. {
  10186. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10188. }
  10189. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10190. {
  10191. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10193. }
  10194. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10195. {
  10196. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10198. }
  10199. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10200. {
  10201. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10203. }
  10204. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10205. {
  10206. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10208. }
  10209. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10210. {
  10211. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10213. }
  10214. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10215. {
  10216. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10218. }
  10219. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10220. {
  10221. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10223. }
  10224. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10225. {
  10226. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10228. }
  10229. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10230. {
  10231. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10233. }
  10234. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10235. {
  10236. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10238. }
  10239. }
  10240. fclose(fp);
  10241. }
  10242. //end_t = clock();
  10243. //printf("End of the big loop, end_t = %ld\n", end_t);
  10244. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10245. //printf("Total time taken by CPU: %f\n", total_t );
  10246. return 0;
  10247. }
  10248. void StoreConfigurationTable(void)
  10249. {
  10250. FILE *outfile;
  10251. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10252. if(outfile == NULL)
  10253. {
  10254. DEBUG_INFO("Error opening file");
  10255. return ;
  10256. }
  10257. /*Core Profile*/
  10258. //AllowOfflineTxForUnknownId
  10259. /*
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10261. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10264. */
  10265. //DEBUG_INFO("data=%s\n",data);
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10267. //AuthorizationCacheEnabled
  10268. /*
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10272. */
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10274. //AuthorizeRemoteTxRequests
  10275. /*
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10279. */
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10281. //BlinkRepeat
  10282. /*
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10286. */
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10288. //ClockAlignedDataInterval
  10289. /*
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10293. */
  10294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10295. //ConnectionTimeOut
  10296. /*
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10300. */
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10302. //GetConfigurationMaxKeys
  10303. /*
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10307. */
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10309. // HeartbeatInterval
  10310. /*
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10314. */
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10316. // LightIntensity
  10317. /*
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10321. */
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10323. // LocalAuthorizeOffline
  10324. /*
  10325. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10328. */
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10330. // LocalPreAuthorize
  10331. /*
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10335. */
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10337. // MaxEnergyOnInvalidId
  10338. /*
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10342. */
  10343. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10345. // MeterValuesAlignedData
  10346. /*
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10350. */
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10352. // MeterValuesAlignedDataMaxLength
  10353. /*
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10357. */
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10359. // MeterValuesSampledData
  10360. /*
  10361. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10364. */
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10366. // MeterValuesSampledDataMaxLength
  10367. /*
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10371. */
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10373. // MeterValueSampleInterval
  10374. /*
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10378. */
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10380. // MinimumStatusDuration
  10381. /*
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10385. */
  10386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10387. // NumberOfConnectors
  10388. /*
  10389. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10392. {
  10393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10394. }
  10395. else
  10396. {
  10397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10398. }
  10399. */
  10400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10401. // ResetRetries
  10402. /*
  10403. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10406. */
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10408. // ConnectorPhaseRotation
  10409. /*
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10413. */
  10414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10415. // ConnectorPhaseRotationMaxLength
  10416. /*
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10420. */
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10422. // StopTransactionOnEVSideDisconnect
  10423. /*
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10427. */
  10428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10429. // StopTransactionOnInvalidId
  10430. /*
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10434. */
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10436. // StopTxnAlignedData
  10437. /*
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10441. */
  10442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10443. // StopTxnAlignedDataMaxLength
  10444. /*
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10448. */
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10450. // StopTxnSampledData
  10451. /*
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10455. */
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10457. // StopTxnSampledDataMaxLength
  10458. /*
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10462. */
  10463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10464. // SupportedFeatureProfiles
  10465. /*
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10469. */
  10470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10471. // SupportedFeatureProfilesMaxLength
  10472. /*
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10476. */
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10478. // TransactionMessageAttempts
  10479. /*
  10480. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10483. */
  10484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10485. // TransactionMessageRetryInterval
  10486. /*
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10490. */
  10491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10492. // UnlockConnectorOnEVSideDisconnect
  10493. /*
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10497. */
  10498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10499. // WebSocketPingInterval
  10500. /*
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10504. */
  10505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10506. //* Local Auth List Management Profile*/
  10507. //LocalAuthListEnabled
  10508. /*
  10509. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10512. */
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10514. //LocalAuthListMaxLength
  10515. /*
  10516. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10519. */
  10520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10521. //SendLocalListMaxLength
  10522. /*
  10523. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10526. */
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10528. //ReserveConnectorZeroSupported
  10529. /*
  10530. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10533. */
  10534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10535. //* Smart Charging Profile */
  10536. //ChargeProfileMaxStackLevel
  10537. /*
  10538. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10541. */
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10543. // ChargingScheduleAllowedChargingRateUnit
  10544. /*
  10545. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10548. */
  10549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10550. // ChargingScheduleMaxPeriods
  10551. /*
  10552. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10555. */
  10556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10557. // ConnectorSwitch3to1PhaseSupported
  10558. /*
  10559. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10562. */
  10563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10564. // MaxChargingProfilesInstalled
  10565. /*
  10566. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10569. */
  10570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10571. fclose(outfile);
  10572. }
  10573. void getKeyValue(char *keyReq)
  10574. {
  10575. int isEmpty = FALSE;
  10576. int isKnowKey = FALSE;
  10577. //int unKnowIndex = 0;
  10578. DEBUG_INFO("getKeyValue \n");
  10579. DEBUG_INFO("keyReq=%s \n",keyReq);
  10580. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10581. isEmpty = TRUE;
  10582. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10583. {
  10584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10587. {
  10588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10589. }
  10590. else
  10591. {
  10592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10593. }
  10594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10595. isKnowKey = TRUE;
  10596. }
  10597. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10598. {
  10599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10602. {
  10603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10604. }
  10605. else
  10606. {
  10607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10608. }
  10609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10610. isKnowKey = TRUE;
  10611. }
  10612. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10613. {
  10614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10617. {
  10618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10619. }
  10620. else
  10621. {
  10622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10623. }
  10624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10625. isKnowKey = TRUE;
  10626. }
  10627. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10628. {
  10629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10632. {
  10633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10634. }
  10635. else
  10636. {
  10637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10638. }
  10639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10640. isKnowKey = TRUE;
  10641. }
  10642. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10643. {
  10644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10647. {
  10648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10649. }
  10650. else
  10651. {
  10652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10653. }
  10654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10655. isKnowKey = TRUE;
  10656. }
  10657. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10658. {
  10659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10662. {
  10663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10664. }
  10665. else
  10666. {
  10667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10668. }
  10669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10670. isKnowKey = TRUE;
  10671. }
  10672. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10673. {
  10674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10677. {
  10678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10679. }
  10680. else
  10681. {
  10682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10683. }
  10684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10685. isKnowKey = TRUE;
  10686. }
  10687. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10688. {
  10689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10692. {
  10693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10694. }
  10695. else
  10696. {
  10697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10698. }
  10699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10700. isKnowKey = TRUE;
  10701. }
  10702. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10703. {
  10704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10707. {
  10708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10709. }
  10710. else
  10711. {
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10713. }
  10714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10715. isKnowKey = TRUE;
  10716. }
  10717. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10718. {
  10719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10722. {
  10723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10724. }
  10725. else
  10726. {
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10728. }
  10729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10730. isKnowKey = TRUE;
  10731. }
  10732. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10733. {
  10734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10737. {
  10738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10739. }
  10740. else
  10741. {
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10743. }
  10744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10745. isKnowKey = TRUE;
  10746. }
  10747. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10748. {
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10752. {
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10754. }
  10755. else
  10756. {
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10758. }
  10759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10760. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10761. isKnowKey = TRUE;
  10762. }
  10763. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10770. }
  10771. else
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10774. }
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10776. isKnowKey = TRUE;
  10777. }
  10778. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10785. }
  10786. else
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10789. }
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10791. isKnowKey = TRUE;
  10792. }
  10793. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10800. }
  10801. else
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10804. }
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10806. isKnowKey = TRUE;
  10807. }
  10808. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10815. }
  10816. else
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10819. }
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10821. isKnowKey = TRUE;
  10822. }
  10823. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10830. }
  10831. else
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10834. }
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10836. isKnowKey = TRUE;
  10837. }
  10838. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10845. }
  10846. else
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10849. }
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10851. isKnowKey = TRUE;
  10852. }
  10853. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10860. }
  10861. else
  10862. {
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10864. }
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10866. isKnowKey = TRUE;
  10867. }
  10868. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10875. }
  10876. else
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10879. }
  10880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10881. isKnowKey = TRUE;
  10882. }
  10883. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10890. }
  10891. else
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10894. }
  10895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10896. isKnowKey = TRUE;
  10897. }
  10898. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10905. }
  10906. else
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10909. }
  10910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10911. isKnowKey = TRUE;
  10912. }
  10913. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10920. }
  10921. else
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10924. }
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10926. isKnowKey = TRUE;
  10927. }
  10928. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10935. }
  10936. else
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10939. }
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10941. isKnowKey = TRUE;
  10942. }
  10943. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10950. }
  10951. else
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10954. }
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10956. isKnowKey = TRUE;
  10957. }
  10958. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10965. }
  10966. else
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10969. }
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10971. isKnowKey = TRUE;
  10972. }
  10973. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10980. }
  10981. else
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10984. }
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10986. isKnowKey = TRUE;
  10987. }
  10988. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10995. }
  10996. else
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10999. }
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11001. isKnowKey = TRUE;
  11002. }
  11003. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11010. }
  11011. else
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11014. }
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11016. isKnowKey = TRUE;
  11017. }
  11018. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11025. }
  11026. else
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11029. }
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11031. isKnowKey = TRUE;
  11032. }
  11033. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11040. }
  11041. else
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11044. }
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11046. isKnowKey = TRUE;
  11047. }
  11048. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11055. }
  11056. else
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11059. }
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11061. isKnowKey = TRUE;
  11062. }
  11063. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11070. }
  11071. else
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11074. }
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11076. isKnowKey = TRUE;
  11077. }
  11078. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11085. }
  11086. else
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11089. }
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11091. isKnowKey = TRUE;
  11092. }
  11093. #if 0
  11094. //For OCTT Test Case
  11095. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11099. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11102. }
  11103. else
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11106. }
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11108. isKnowKey = TRUE;
  11109. }
  11110. #endif
  11111. #if 1
  11112. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11116. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11119. }
  11120. else
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11123. }
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11125. isKnowKey = TRUE;
  11126. }
  11127. #endif
  11128. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11132. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11135. }
  11136. else
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11139. }
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11141. isKnowKey = TRUE;
  11142. }
  11143. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11147. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11150. }
  11151. else
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11154. }
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11156. isKnowKey = TRUE;
  11157. }
  11158. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11162. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11165. }
  11166. else
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11169. }
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11171. isKnowKey = TRUE;
  11172. }
  11173. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11177. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11180. }
  11181. else
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11184. }
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11186. isKnowKey = TRUE;
  11187. }
  11188. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11192. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11195. }
  11196. else
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11199. }
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11201. isKnowKey = TRUE;
  11202. }
  11203. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11207. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11210. }
  11211. else
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11214. }
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11216. isKnowKey = TRUE;
  11217. }
  11218. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11222. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11225. }
  11226. else
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11229. }
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11231. isKnowKey = TRUE;
  11232. }
  11233. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11237. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11240. }
  11241. else
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11244. }
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11246. isKnowKey = TRUE;
  11247. }
  11248. //=========================================================
  11249. if(!isEmpty && !isKnowKey)
  11250. {
  11251. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11252. strcpy(unknownkey[UnknownKeynum], keyReq);
  11253. UnknownKeynum = UnknownKeynum + 1;
  11254. }
  11255. }
  11256. void processUnkownKey(void)
  11257. {
  11258. DEBUG_INFO("processUnkownKey\n");
  11259. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11260. for(int index=0; index < UnknownKeynum; index++)
  11261. {
  11262. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11263. {
  11264. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11265. }
  11266. }
  11267. }
  11268. int setKeyValue(char *key, char *value)
  11269. {
  11270. int isSuccess = NotSupported;
  11271. int check_ascii=0;
  11272. char str[10]={0};
  11273. #ifdef Debug
  11274. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11275. #endif
  11276. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11277. {
  11278. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11280. {
  11281. strcpy(str, (const char*)value);
  11282. for(int i = 0; str[i]; i++){
  11283. str[i] = tolower(str[i]);
  11284. }
  11285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11286. isSuccess = ConfigurationStatus_Accepted;
  11287. }
  11288. else
  11289. {
  11290. isSuccess = ConfigurationStatus_Rejected;
  11291. }
  11292. }
  11293. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11294. {
  11295. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11297. {
  11298. strcpy(str, (const char*)value);
  11299. for(int i = 0; str[i]; i++){
  11300. str[i] = tolower(str[i]);
  11301. }
  11302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11303. isSuccess = ConfigurationStatus_Accepted;
  11304. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11305. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11306. }
  11307. else
  11308. {
  11309. isSuccess = ConfigurationStatus_Rejected;
  11310. }
  11311. }
  11312. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11313. {
  11314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11315. {
  11316. strcpy(str, (const char*)value);
  11317. for(int i = 0; str[i]; i++)
  11318. {
  11319. str[i] = tolower(str[i]);
  11320. }
  11321. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11323. isSuccess = ConfigurationStatus_Accepted;
  11324. }
  11325. else
  11326. {
  11327. isSuccess = ConfigurationStatus_Rejected;
  11328. }
  11329. }
  11330. if(strcmp(key, "BlinkRepeat") == 0)
  11331. {
  11332. //Charger.BlinkRepeat = Integer.parseInt(value);
  11333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11334. {
  11335. check_ascii = value[0];
  11336. if( (check_ascii < 48) || (check_ascii > 57) )
  11337. {
  11338. isSuccess = ConfigurationStatus_Rejected;
  11339. }
  11340. else
  11341. {
  11342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11343. isSuccess = ConfigurationStatus_Accepted;
  11344. }
  11345. }
  11346. else
  11347. {
  11348. isSuccess = ConfigurationStatus_Rejected;
  11349. }
  11350. }
  11351. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11352. {
  11353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11354. {
  11355. check_ascii = value[0];
  11356. if( (check_ascii < 48) || (check_ascii > 57) )
  11357. {
  11358. isSuccess = ConfigurationStatus_Rejected;
  11359. }
  11360. else
  11361. {
  11362. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11364. isSuccess = ConfigurationStatus_Accepted;
  11365. }
  11366. }
  11367. else
  11368. {
  11369. isSuccess = ConfigurationStatus_Rejected;
  11370. }
  11371. }
  11372. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11373. {
  11374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11375. {
  11376. check_ascii = value[0];
  11377. if( (check_ascii < 48) || (check_ascii > 57) )
  11378. {
  11379. isSuccess = ConfigurationStatus_Rejected;
  11380. }
  11381. else
  11382. {
  11383. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11385. isSuccess = ConfigurationStatus_Accepted;
  11386. }
  11387. }
  11388. else
  11389. {
  11390. isSuccess = ConfigurationStatus_Rejected;
  11391. }
  11392. }
  11393. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11394. {
  11395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11396. {
  11397. check_ascii = value[0];
  11398. if( (check_ascii < 48) || (check_ascii > 57) )
  11399. {
  11400. isSuccess = ConfigurationStatus_Rejected;
  11401. }
  11402. else
  11403. {
  11404. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11406. isSuccess = ConfigurationStatus_Accepted;
  11407. }
  11408. }
  11409. else
  11410. {
  11411. isSuccess = ConfigurationStatus_Rejected;
  11412. }
  11413. }
  11414. if(strcmp(key, "HeartbeatInterval") == 0)
  11415. {
  11416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11417. {
  11418. check_ascii = value[0];
  11419. if( (check_ascii < 48) || (check_ascii > 57) )
  11420. {
  11421. isSuccess = ConfigurationStatus_Rejected;
  11422. }
  11423. else
  11424. {
  11425. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11427. HeartBeatWaitTime = atoi(value);
  11428. isSuccess = ConfigurationStatus_Accepted;
  11429. }
  11430. }
  11431. else
  11432. {
  11433. isSuccess = ConfigurationStatus_Rejected;
  11434. }
  11435. }
  11436. if(strcmp(key, "LightIntensity") == 0)
  11437. {
  11438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11439. {
  11440. check_ascii = value[0];
  11441. if( (check_ascii < 48) || (check_ascii > 57) )
  11442. {
  11443. isSuccess = ConfigurationStatus_Rejected;
  11444. }
  11445. else
  11446. {
  11447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11448. isSuccess = ConfigurationStatus_Accepted;
  11449. }
  11450. }
  11451. else
  11452. {
  11453. isSuccess = ConfigurationStatus_Rejected;
  11454. }
  11455. }
  11456. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11457. {
  11458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11459. {
  11460. strcpy(str, (const char*)value);
  11461. for(int i = 0; str[i]; i++)
  11462. {
  11463. str[i] = tolower(str[i]);
  11464. }
  11465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11466. isSuccess = ConfigurationStatus_Accepted;
  11467. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11468. }
  11469. else
  11470. {
  11471. isSuccess = ConfigurationStatus_Rejected;
  11472. }
  11473. }
  11474. if(strcmp(key, "LocalPreAuthorize") == 0)
  11475. {
  11476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11477. {
  11478. strcpy(str, (const char*)value);
  11479. for(int i = 0; str[i]; i++)
  11480. {
  11481. str[i] = tolower(str[i]);
  11482. }
  11483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11484. isSuccess = ConfigurationStatus_Accepted;
  11485. }
  11486. else
  11487. {
  11488. isSuccess = ConfigurationStatus_Rejected;
  11489. }
  11490. }
  11491. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11492. {
  11493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11494. {
  11495. check_ascii = value[0];
  11496. if( (check_ascii < 48) || (check_ascii > 57) )
  11497. {
  11498. isSuccess = ConfigurationStatus_Rejected;
  11499. }
  11500. else
  11501. {
  11502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11503. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11504. isSuccess = ConfigurationStatus_Accepted;
  11505. }
  11506. }
  11507. else
  11508. {
  11509. isSuccess = ConfigurationStatus_Rejected;
  11510. }
  11511. }
  11512. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11513. {
  11514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11515. {
  11516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11517. isSuccess = ConfigurationStatus_Accepted;
  11518. }
  11519. else
  11520. {
  11521. isSuccess = ConfigurationStatus_Rejected;
  11522. }
  11523. }
  11524. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11525. {
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11527. {
  11528. check_ascii = value[0];
  11529. if( (check_ascii < 48) || (check_ascii > 57) )
  11530. {
  11531. isSuccess = ConfigurationStatus_Rejected;
  11532. }
  11533. else
  11534. {
  11535. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11537. isSuccess = ConfigurationStatus_Accepted;
  11538. }
  11539. }
  11540. else
  11541. {
  11542. isSuccess = ConfigurationStatus_Rejected;
  11543. }
  11544. }
  11545. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11546. {
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11548. {
  11549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11550. isSuccess = ConfigurationStatus_Accepted;
  11551. }
  11552. else
  11553. {
  11554. isSuccess = ConfigurationStatus_Rejected;
  11555. }
  11556. }
  11557. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11558. {
  11559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11560. {
  11561. check_ascii = value[0];
  11562. if( (check_ascii < 48) || (check_ascii > 57) )
  11563. {
  11564. isSuccess = ConfigurationStatus_Rejected;
  11565. }
  11566. else
  11567. {
  11568. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11570. isSuccess = ConfigurationStatus_Accepted;
  11571. }
  11572. }
  11573. else
  11574. {
  11575. isSuccess = ConfigurationStatus_Rejected;
  11576. }
  11577. }
  11578. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11579. {
  11580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11581. {
  11582. check_ascii = value[0];
  11583. if( (check_ascii < 48) || (check_ascii > 57) )
  11584. {
  11585. isSuccess = ConfigurationStatus_Rejected;
  11586. }
  11587. else
  11588. {
  11589. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11591. isSuccess = ConfigurationStatus_Accepted;
  11592. }
  11593. }
  11594. else
  11595. {
  11596. isSuccess = ConfigurationStatus_Rejected;
  11597. }
  11598. }
  11599. if(strcmp(key, "MinimumStatusDuration") == 0)
  11600. {
  11601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11602. {
  11603. check_ascii = value[0];
  11604. if( (check_ascii < 48) || (check_ascii > 57) )
  11605. {
  11606. isSuccess = ConfigurationStatus_Rejected;
  11607. }
  11608. else
  11609. {
  11610. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11611. {
  11612. isSuccess = ConfigurationStatus_Rejected;
  11613. }
  11614. else
  11615. {
  11616. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11618. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11619. isSuccess = ConfigurationStatus_Accepted;
  11620. }
  11621. }
  11622. }
  11623. else
  11624. {
  11625. isSuccess = ConfigurationStatus_Rejected;
  11626. }
  11627. }
  11628. if(strcmp(key, "NumberOfConnectors") == 0)
  11629. {
  11630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11631. {
  11632. check_ascii = value[0];
  11633. if( (check_ascii < 48) || (check_ascii > 57) )
  11634. {
  11635. isSuccess = ConfigurationStatus_Rejected;
  11636. }
  11637. else
  11638. {
  11639. //Charger.ResetRetries = Integer.parseInt(value);
  11640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11641. isSuccess = ConfigurationStatus_Accepted;
  11642. }
  11643. }
  11644. else
  11645. {
  11646. isSuccess = ConfigurationStatus_Rejected;
  11647. }
  11648. }
  11649. if(strcmp(key, "ResetRetries") == 0)
  11650. {
  11651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11652. {
  11653. check_ascii = value[0];
  11654. if( (check_ascii < 48) || (check_ascii > 57) )
  11655. {
  11656. isSuccess = ConfigurationStatus_Rejected;
  11657. }
  11658. else
  11659. {
  11660. //Charger.ResetRetries = Integer.parseInt(value);
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11662. isSuccess = ConfigurationStatus_Accepted;
  11663. }
  11664. }
  11665. else
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. }
  11670. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11671. {
  11672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11673. {
  11674. strcpy(str, (const char*)value);
  11675. for(int i = 0; str[i]; i++)
  11676. {
  11677. str[i] = tolower(str[i]);
  11678. }
  11679. if(strcmp(str, "notapplicable")== 0)
  11680. {
  11681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11682. isSuccess = ConfigurationStatus_Accepted;
  11683. }
  11684. else if(strcmp(str, "unknown")== 0)
  11685. {
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11687. isSuccess = ConfigurationStatus_Accepted;
  11688. }
  11689. else if(strcmp(str, "rst")== 0)
  11690. {
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11692. isSuccess = ConfigurationStatus_Accepted;
  11693. }
  11694. else if(strcmp(str, "rts")== 0)
  11695. {
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11697. isSuccess = ConfigurationStatus_Accepted;
  11698. }
  11699. else if(strcmp(str, "srt")== 0)
  11700. {
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11702. isSuccess = ConfigurationStatus_Accepted;
  11703. }
  11704. else if(strcmp(str, "str")== 0)
  11705. {
  11706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11707. isSuccess = ConfigurationStatus_Accepted;
  11708. }
  11709. else if(strcmp(str, "trs")== 0)
  11710. {
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11712. isSuccess = ConfigurationStatus_Accepted;
  11713. }
  11714. else if(strcmp(str, "tsr")== 0)
  11715. {
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11717. isSuccess = ConfigurationStatus_Accepted;
  11718. }
  11719. else
  11720. {
  11721. isSuccess = ConfigurationStatus_Rejected;
  11722. }
  11723. }
  11724. else
  11725. {
  11726. isSuccess = ConfigurationStatus_Rejected;
  11727. }
  11728. }
  11729. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11730. {
  11731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11732. {
  11733. check_ascii = value[0];
  11734. if( (check_ascii < 48) || (check_ascii > 57) )
  11735. {
  11736. isSuccess = ConfigurationStatus_Rejected;
  11737. }
  11738. else
  11739. {
  11740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11741. isSuccess = ConfigurationStatus_Accepted;
  11742. }
  11743. }
  11744. else
  11745. {
  11746. isSuccess = ConfigurationStatus_Rejected;
  11747. }
  11748. }
  11749. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11750. {
  11751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11752. {
  11753. strcpy(str, (const char*)value);
  11754. for(int i = 0; str[i]; i++)
  11755. {
  11756. str[i] = tolower(str[i]);
  11757. }
  11758. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11760. isSuccess = ConfigurationStatus_Accepted;
  11761. }
  11762. else
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. }
  11767. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11768. {
  11769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11770. {
  11771. strcpy(str, (const char*)value);
  11772. for(int i = 0; str[i]; i++)
  11773. {
  11774. str[i] = tolower(str[i]);
  11775. }
  11776. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11778. isSuccess = ConfigurationStatus_Accepted;
  11779. }
  11780. else
  11781. {
  11782. isSuccess = ConfigurationStatus_Rejected;
  11783. }
  11784. }
  11785. if(strcmp(key, "StopTxnAlignedData") == 0)
  11786. {
  11787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11788. {
  11789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11790. isSuccess = ConfigurationStatus_Accepted;
  11791. }
  11792. else
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. }
  11797. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11798. {
  11799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11800. {
  11801. check_ascii = value[0];
  11802. if( (check_ascii < 48) || (check_ascii > 57) )
  11803. {
  11804. isSuccess = ConfigurationStatus_Rejected;
  11805. }
  11806. else
  11807. {
  11808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11809. isSuccess = ConfigurationStatus_Accepted;
  11810. }
  11811. }
  11812. else
  11813. {
  11814. isSuccess = ConfigurationStatus_Rejected;
  11815. }
  11816. }
  11817. if(strcmp(key, "StopTxnSampledData") == 0)
  11818. {
  11819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11820. {
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. else
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. }
  11829. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11830. {
  11831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11832. {
  11833. check_ascii = value[0];
  11834. if( (check_ascii < 48) || (check_ascii > 57) )
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. else
  11839. {
  11840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11841. isSuccess = ConfigurationStatus_Accepted;
  11842. }
  11843. }
  11844. else
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. }
  11849. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11850. {
  11851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11852. {
  11853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11854. isSuccess = ConfigurationStatus_Accepted;
  11855. }
  11856. else
  11857. {
  11858. isSuccess = ConfigurationStatus_Rejected;
  11859. }
  11860. }
  11861. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11862. {
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11873. isSuccess = ConfigurationStatus_Accepted;
  11874. }
  11875. }
  11876. else
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. }
  11881. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11882. {
  11883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11884. {
  11885. check_ascii = value[0];
  11886. if( (check_ascii < 48) || (check_ascii > 57) )
  11887. {
  11888. isSuccess = ConfigurationStatus_Rejected;
  11889. }
  11890. else
  11891. {
  11892. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11894. TransactionMessageAttemptsValue = atoi(value);
  11895. isSuccess = ConfigurationStatus_Accepted;
  11896. }
  11897. }
  11898. else
  11899. {
  11900. isSuccess = ConfigurationStatus_Rejected;
  11901. }
  11902. }
  11903. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11904. {
  11905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11906. {
  11907. check_ascii = value[0];
  11908. if( (check_ascii < 48) || (check_ascii > 57) )
  11909. {
  11910. isSuccess = ConfigurationStatus_Rejected;
  11911. }
  11912. else
  11913. {
  11914. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11916. TransactionMessageRetryIntervalValue = atoi(value);
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11928. {
  11929. strcpy(str, (const char*)value);
  11930. for(int i = 0; str[i]; i++)
  11931. {
  11932. str[i] = tolower(str[i]);
  11933. }
  11934. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11936. isSuccess = ConfigurationStatus_Accepted;
  11937. }
  11938. else
  11939. {
  11940. isSuccess = ConfigurationStatus_Rejected;
  11941. }
  11942. }
  11943. if(strcmp(key, "WebSocketPingInterval") == 0)
  11944. {
  11945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11946. {
  11947. check_ascii = value[0];
  11948. if( (check_ascii < 48) || (check_ascii > 57) )
  11949. {
  11950. isSuccess = ConfigurationStatus_Rejected;
  11951. }
  11952. else
  11953. {
  11954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11955. isSuccess = ConfigurationStatus_Accepted;
  11956. }
  11957. }
  11958. else
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. }
  11963. #if 0
  11964. //For OCPP Test Case
  11965. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11966. {
  11967. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11968. {
  11969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11970. isSuccess = ConfigurationStatus_Accepted;
  11971. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11972. }
  11973. else
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. }
  11978. #endif
  11979. #if 1
  11980. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11981. {
  11982. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11983. {
  11984. strcpy(str, (const char*)value);
  11985. for(int i = 0; str[i]; i++)
  11986. {
  11987. str[i] = tolower(str[i]);
  11988. }
  11989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11990. isSuccess = ConfigurationStatus_Accepted;
  11991. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11992. }
  11993. else
  11994. {
  11995. isSuccess = ConfigurationStatus_Rejected;
  11996. }
  11997. }
  11998. #endif
  11999. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12000. {
  12001. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12002. {
  12003. check_ascii = value[0];
  12004. if( (check_ascii < 48) || (check_ascii > 57) )
  12005. {
  12006. isSuccess = ConfigurationStatus_Rejected;
  12007. }
  12008. else
  12009. {
  12010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12011. isSuccess = ConfigurationStatus_Accepted;
  12012. }
  12013. }
  12014. else
  12015. {
  12016. isSuccess = ConfigurationStatus_Rejected;
  12017. }
  12018. }
  12019. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12020. {
  12021. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12022. {
  12023. check_ascii = value[0];
  12024. if( (check_ascii < 48) || (check_ascii > 57) )
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. else
  12029. {
  12030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12031. isSuccess = ConfigurationStatus_Accepted;
  12032. }
  12033. }
  12034. else
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. }
  12039. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12040. {
  12041. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12042. {
  12043. strcpy(str, (const char*)value);
  12044. for(int i = 0; str[i]; i++)
  12045. {
  12046. str[i] = tolower(str[i]);
  12047. }
  12048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. else
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. }
  12056. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12057. {
  12058. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12059. {
  12060. check_ascii = value[0];
  12061. if( (check_ascii < 48) || (check_ascii > 57) )
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. else
  12066. {
  12067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12068. isSuccess = ConfigurationStatus_Accepted;
  12069. }
  12070. }
  12071. else
  12072. {
  12073. isSuccess = ConfigurationStatus_Rejected;
  12074. }
  12075. }
  12076. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12077. {
  12078. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12079. {
  12080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12081. isSuccess = ConfigurationStatus_Accepted;
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12091. {
  12092. check_ascii = value[0];
  12093. if( (check_ascii < 48) || (check_ascii > 57) )
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. else
  12098. {
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12111. {
  12112. strcpy(str, (const char*)value);
  12113. for(int i = 0; str[i]; i++)
  12114. {
  12115. str[i] = tolower(str[i]);
  12116. }
  12117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12118. isSuccess = ConfigurationStatus_Accepted;
  12119. }
  12120. else
  12121. {
  12122. isSuccess = ConfigurationStatus_Rejected;
  12123. }
  12124. }
  12125. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12126. {
  12127. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12128. {
  12129. check_ascii = value[0];
  12130. if( (check_ascii < 48) || (check_ascii > 57) )
  12131. {
  12132. isSuccess = ConfigurationStatus_Rejected;
  12133. }
  12134. else
  12135. {
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. }
  12140. else
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. }
  12145. return isSuccess;
  12146. }
  12147. int updateSetting(char *key, char *value)
  12148. {
  12149. mtrace();
  12150. int isSuccess = FALSE;
  12151. char string[1000]={0}, buffer[1000]={0};
  12152. char strtemp[50]={0};
  12153. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12154. int pos, c = 0;
  12155. char *loc;
  12156. int pos1=0;
  12157. FILE *f = fopen("/var/www/settings1", "r");
  12158. if(f == NULL)
  12159. {
  12160. #ifdef Debug
  12161. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12162. #endif
  12163. return isSuccess;
  12164. }
  12165. fseek(f, 0, SEEK_END);
  12166. long fsize = ftell(f);
  12167. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12168. fread(string, 1, fsize, f);
  12169. fclose(f);
  12170. string[fsize] = 0;
  12171. loc = strstr(string, key);
  12172. if(loc != NULL)
  12173. {
  12174. DEBUG_INFO("key exist!\n");
  12175. pos = loc - string-1;
  12176. f = fopen("/var/www/settings1", "w");
  12177. strncpy(buffer, string, pos);
  12178. fprintf(f, "%s", buffer);
  12179. memset(sstr ,0, sizeof(sstr) );
  12180. c = 0;
  12181. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12182. {
  12183. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12184. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12185. c++;
  12186. }
  12187. sstr[c] = '\0';
  12188. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12189. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12190. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12191. memset(buffer ,0, sizeof(buffer) );
  12192. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12193. //printf("buffer=%s",buffer);
  12194. fprintf(f, "%s", buffer);
  12195. fclose(f);
  12196. }
  12197. else
  12198. {
  12199. printf("key not exist!\n");
  12200. f = fopen("/var/www/settings1", "w+");
  12201. fputs(string, f);
  12202. fseek(f, -1, SEEK_CUR);
  12203. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12204. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12205. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12206. fclose(f);
  12207. }
  12208. isSuccess = TRUE;
  12209. return isSuccess;
  12210. }
  12211. int TransactionMessageAttemptsGet(void)
  12212. {
  12213. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12214. }
  12215. int FirstHeartBeatResponse(void)
  12216. {
  12217. return FirstHeartBeat;
  12218. }
  12219. int TransactionMessageRetryIntervalGet(void)
  12220. {
  12221. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12222. }
  12223. #define SA struct sockaddr
  12224. #define MAXBUF 1024
  12225. //static int m_socket_data;
  12226. //static int sockfd;
  12227. int ReadHttpStatus(int sock){
  12228. //char c;
  12229. char buff[1024]="",*ptr=buff+1;
  12230. int bytes_received, status;
  12231. DEBUG_INFO("Begin Response ..\n");
  12232. while((bytes_received = recv(sock, ptr, 1, 0))){
  12233. if(bytes_received==-1){
  12234. perror("ReadHttpStatus");
  12235. exit(1);
  12236. }
  12237. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12238. ptr++;
  12239. }
  12240. *ptr=0;
  12241. ptr=buff+1;
  12242. sscanf(ptr,"%*s %d ", &status);
  12243. DEBUG_INFO("%s\n",ptr);
  12244. DEBUG_INFO("status=%d\n",status);
  12245. DEBUG_INFO("End Response ..\n");
  12246. return (bytes_received>0)?status:0;
  12247. }
  12248. //the only filed that it parsed is 'Content-Length'
  12249. int ParseHeader(int sock){
  12250. //char c;
  12251. char buff[1024]="",*ptr=buff+4;
  12252. int bytes_received;
  12253. DEBUG_INFO("Begin HEADER ..\n");
  12254. while((bytes_received = recv(sock, ptr, 1, 0))){
  12255. if(bytes_received==-1){
  12256. perror("Parse Header");
  12257. exit(1);
  12258. }
  12259. if(
  12260. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12261. (ptr[-1]=='\r') && (*ptr=='\n' )
  12262. ) break;
  12263. ptr++;
  12264. }
  12265. *ptr=0;
  12266. ptr=buff+4;
  12267. //printf("%s",ptr);
  12268. if(bytes_received){
  12269. ptr=strstr(ptr,"Content-Length:");
  12270. if(ptr){
  12271. sscanf(ptr,"%*s %d",&bytes_received);
  12272. }else
  12273. bytes_received=-1; //unknown size
  12274. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12275. }
  12276. DEBUG_INFO("End HEADER ..\n");
  12277. return bytes_received ;
  12278. }
  12279. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12280. {
  12281. char rmFileCmd[100]={0};
  12282. char FilePath[100]={0};
  12283. char ftpbuf[200];
  12284. int systemresult;
  12285. //DEBUG_INFO("filename=%s\n",filename);
  12286. //DEBUG_INFO("url=%s\n",url);
  12287. sprintf(FilePath,"/mnt/%s",filename);
  12288. if((access(FilePath,F_OK))!=-1)
  12289. {
  12290. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12291. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12292. system(rmFileCmd);
  12293. }
  12294. memset(ftpbuf, 0, sizeof(ftpbuf));
  12295. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12296. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12297. systemresult = system(ftpbuf);
  12298. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12299. if(systemresult != 0)
  12300. {
  12301. DEBUG_INFO("http DownLoad error!\n");
  12302. return FALSE;
  12303. }
  12304. return TRUE;
  12305. }
  12306. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12307. {
  12308. char rmFileCmd[100]={0};
  12309. char FilePath[100]={0};
  12310. char ftpbuf[200];
  12311. int systemresult;
  12312. //char temp[100];
  12313. #if 0
  12314. struct hostent* server;
  12315. char *IPbuffer;
  12316. server = gethostbyname(location);
  12317. // To convert an Internet network
  12318. // address into ASCII string
  12319. IPbuffer = inet_ntoa(*((struct in_addr*)
  12320. server->h_addr_list[0]));
  12321. #endif
  12322. sprintf(FilePath,"/mnt/%s",filename);
  12323. if((access(FilePath,F_OK))!=-1)
  12324. {
  12325. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12326. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12327. system(rmFileCmd);
  12328. }
  12329. memset(ftpbuf, 0, sizeof(ftpbuf));
  12330. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12331. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12332. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12333. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12334. systemresult = system(ftpbuf);
  12335. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12336. if(systemresult != 0)
  12337. {
  12338. printf("wget error!\n");
  12339. return FALSE;
  12340. }
  12341. return TRUE;
  12342. }
  12343. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12344. {
  12345. char rmFileCmd[100]={0};
  12346. char FilePath[100]={0};
  12347. char ftpbuf[200];
  12348. char filenametemp[60]={0};
  12349. int systemresult;
  12350. //DEBUG_INFO("filename=%s\n",filename);
  12351. //DEBUG_INFO("url=%s\n",url);
  12352. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12353. if((access(FilePath,F_OK))!=-1)
  12354. {
  12355. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12356. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12357. system(rmFileCmd);
  12358. }
  12359. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12360. if(fp == NULL)
  12361. {
  12362. DEBUG_INFO("log is NULL\n");
  12363. return FALSE;
  12364. }
  12365. else
  12366. {
  12367. fprintf(fp, "%s\n", url);
  12368. sscanf(filename, "%*2[.]%s", filenametemp);
  12369. fprintf(fp, "%s\n", filenametemp);
  12370. fclose(fp);
  12371. }
  12372. memset(ftpbuf, 0, sizeof(ftpbuf));
  12373. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12374. systemresult = system(ftpbuf);
  12375. DEBUG_INFO("systemresult=%d\n",systemresult);
  12376. if(systemresult != 0)
  12377. {
  12378. DEBUG_INFO("http upload error!\n");
  12379. return FALSE;
  12380. }
  12381. return TRUE;
  12382. }
  12383. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12384. {
  12385. struct hostent* server;
  12386. char *IPbuffer;
  12387. char ftpbuf[200];
  12388. int systemresult;
  12389. // To retrieve host information
  12390. server = gethostbyname(location);
  12391. // To convert an Internet network
  12392. // address into ASCII string
  12393. IPbuffer = inet_ntoa(*((struct in_addr*)
  12394. server->h_addr_list[0]));
  12395. memset(ftpbuf, 0, sizeof(ftpbuf));
  12396. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12397. /* format : ftpput -u username -p passwd IP target source*/
  12398. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12399. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12400. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12401. systemresult = system(ftpbuf);
  12402. DEBUG_INFO("systemresult=%d\n",systemresult);
  12403. if(systemresult != 0)
  12404. {
  12405. DEBUG_INFO("ftpput error!\n");
  12406. return FALSE;
  12407. }
  12408. return TRUE;
  12409. }
  12410. int SettingChargingRecord(int target, int transactionId)
  12411. {
  12412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12413. {
  12414. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12415. {
  12416. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12417. {
  12418. addBuff(target, transactionId, 0);
  12419. return TRUE;
  12420. }
  12421. }
  12422. for (int index = 0; index < CCS_QUANTITY; index++)
  12423. {
  12424. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12425. {
  12426. addBuff(target, transactionId, 0);
  12427. return TRUE;
  12428. }
  12429. }
  12430. for (int index = 0; index < GB_QUANTITY; index++)
  12431. {
  12432. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12433. {
  12434. addBuff(target, transactionId, 0);
  12435. return TRUE;
  12436. }
  12437. }
  12438. }
  12439. else
  12440. {
  12441. for (int index = 0; index < AC_QUANTITY; index++)
  12442. {
  12443. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12444. {
  12445. addBuff(target, transactionId, 0);
  12446. return TRUE;
  12447. }
  12448. }
  12449. }
  12450. return FALSE;
  12451. }
  12452. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12453. {
  12454. int isSuccess = FALSE;
  12455. //char *query = NULL;
  12456. sqlite3_stmt *stmt;
  12457. int rc; // return code
  12458. char str[20];
  12459. sprintf(str,"%d",user_id);
  12460. 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 */
  12461. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12462. rc = sqlite3_step(stmt); /* 3 */
  12463. if (rc != SQLITE_DONE) {
  12464. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12465. goto out;
  12466. }
  12467. sqlite3_finalize(stmt);
  12468. // free(query);
  12469. out:
  12470. //----------------------
  12471. // close SQLite database
  12472. //----------------------
  12473. sqlite3_close(db);
  12474. printf("database closed.\n");
  12475. return isSuccess;
  12476. }
  12477. /**
  12478. * Place the contents of the specified file into a memory buffer
  12479. *
  12480. * @param[in] filename The path and name of the file to read
  12481. * @param[out] filebuffer A pointer to the contents in memory
  12482. * @return status 0 success, 1 on failure
  12483. */
  12484. int get_file_contents(const char* filename, char** outbuffer) {
  12485. FILE* file = NULL;
  12486. long filesize;
  12487. const int blocksize = 1;
  12488. size_t readsize;
  12489. char* filebuffer;
  12490. // Open the file
  12491. file = fopen(filename, "r");
  12492. if (NULL == file)
  12493. {
  12494. printf("'%s' not opened\n", filename);
  12495. exit(EXIT_FAILURE);
  12496. }
  12497. // Determine the file size
  12498. fseek(file, 0, SEEK_END);
  12499. filesize = ftell(file);
  12500. rewind (file);
  12501. // Allocate memory for the file contents
  12502. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12503. *outbuffer = filebuffer;
  12504. if (filebuffer == NULL)
  12505. {
  12506. fputs ("malloc out-of-memory", stderr);
  12507. exit(EXIT_FAILURE);
  12508. }
  12509. // Read in the file
  12510. readsize = fread(filebuffer, blocksize, filesize, file);
  12511. if (readsize != filesize)
  12512. {
  12513. fputs ("didn't read file completely",stderr);
  12514. exit(EXIT_FAILURE);
  12515. }
  12516. // Clean exit
  12517. fclose(file);
  12518. return EXIT_SUCCESS;
  12519. }
  12520. static int selectSqlCount = 0;
  12521. static int callback(void *data, int argc, char **argv, char **azColName){
  12522. int i;
  12523. //printf("%s: ", (const char*)data);
  12524. selectSqlCount = argc;
  12525. for(i = 0; i<argc; i++){
  12526. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12527. }
  12528. //printf("\n");
  12529. return 0;
  12530. }
  12531. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12532. //int i;
  12533. //printf("%s:\n", (const char*)data);
  12534. localversion = argv[5] ? atoi(argv[5]) : 0;
  12535. //printf("localversion=%d\n", localversion);
  12536. return 0;
  12537. }
  12538. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12539. //int i;
  12540. //printf("%s:\n", (const char*)data);
  12541. //idTag
  12542. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12543. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12544. //parentIdTag
  12545. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12546. //expir_date
  12547. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12548. //status
  12549. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12550. //version
  12551. idTagQuery.listVersionInt = atoi(argv[5]);
  12552. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12553. return 0;
  12554. }
  12555. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12556. #if 0
  12557. int i;
  12558. //printf("%s:\n", (const char*)data);
  12559. for(i=0; i<argc; i++){
  12560. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12561. }
  12562. //printf("");
  12563. #endif
  12564. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12565. // printf("localversion=%d\n", localversion);
  12566. return 0;
  12567. }
  12568. /** sqlite3_exec的回调。
  12569. *
  12570. * 向控制台打印查询的结果。
  12571. *
  12572. * @param in data 传递给回调函数的数据。
  12573. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12574. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12575. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12576. * @return 状态码。
  12577. */
  12578. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12579. {
  12580. for (int i = 0; i < n_columns; i++)
  12581. {
  12582. DEBUG_INFO("%s/t", col_values[i]);
  12583. }
  12584. DEBUG_INFO("/n");
  12585. return 0;
  12586. }
  12587. void OCPP_getListVerion()
  12588. {
  12589. int rc = 0;
  12590. // const char* data = "Callback function called";
  12591. char sql[100];
  12592. char zErrMsg[100];
  12593. memset(sql, 0, 100);
  12594. memset(zErrMsg, 0, 100);
  12595. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12596. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12597. /* Execute SQL statement */
  12598. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12599. DEBUG_INFO("rc=%d\n",rc);
  12600. if( rc != SQLITE_OK ){
  12601. DEBUG_INFO("SQL error: %s", zErrMsg);
  12602. //sqlite3_free(zErrMsg);
  12603. }
  12604. }
  12605. void OCPP_getIdTag(char idTag[])
  12606. {
  12607. int rc = 0;
  12608. // const char* data = "Callback function called";
  12609. char sql[100];
  12610. char zErrMsg[100];
  12611. memset(sql, 0, 100);
  12612. memset(zErrMsg, 0, 100);
  12613. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12614. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12615. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12616. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12617. /* Execute SQL statement */
  12618. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12619. if( rc != SQLITE_OK ){
  12620. DEBUG_INFO("SQL error: %s", zErrMsg);
  12621. //sqlite3_free(zErrMsg);
  12622. }
  12623. //return ver;
  12624. }
  12625. void OCPP_get_TableAuthlocalAllData(void)
  12626. {
  12627. int rc = 0;
  12628. // const char* data = "Callback function called";
  12629. char sql[100];
  12630. char zErrMsg[100];
  12631. memset(sql, 0, 100);
  12632. memset(zErrMsg, 0, 100);
  12633. sprintf(sql,"select * from ocpp_auth_local ");
  12634. /* Execute SQL statement */
  12635. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12636. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12637. if( rc != SQLITE_OK ){
  12638. DEBUG_INFO("SQL error: %s", zErrMsg);
  12639. //sqlite3_free(zErrMsg);
  12640. }
  12641. //return ver;
  12642. }
  12643. int OCPP_cleanLocalList()
  12644. {
  12645. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12646. char *errMsg = 0;
  12647. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12648. if (SQLITE_OK != rc)
  12649. {
  12650. DEBUG_INFO("%s\n",errMsg);
  12651. return FALSE;
  12652. }
  12653. else
  12654. {
  12655. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12656. }
  12657. return TRUE;
  12658. }
  12659. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12660. {
  12661. int isSuccess = FALSE;
  12662. int ret = 0;
  12663. //const char* data = "Callback function called";
  12664. char sql[300];
  12665. char zErrMsg[200];
  12666. memset(sql, 0, 300);
  12667. memset(zErrMsg, 0, 200);
  12668. 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);
  12669. //* Execute SQL statement */
  12670. //zErrMsg = 0;
  12671. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12672. if( ret != SQLITE_OK ){
  12673. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12674. // free(zErrMsg);
  12675. // free(sql);
  12676. return isSuccess;
  12677. }
  12678. memset(sql, 0, 300);
  12679. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12680. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12681. if( ret != SQLITE_OK ){
  12682. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12683. // free(zErrMsg);
  12684. // free(sql);
  12685. return isSuccess;
  12686. }
  12687. // DEBUG_INFO("successfully Insert records created\n");
  12688. isSuccess = TRUE;
  12689. return isSuccess;
  12690. }
  12691. void OCPP_deleteIdTag(char idTag[])
  12692. {
  12693. //int ver = 0;
  12694. //int isSuccess = FALSE;
  12695. int rc = 0;
  12696. char sql[100];
  12697. char zErrMsg[100];
  12698. memset(sql, 0, 100);
  12699. memset(zErrMsg, 0, 100);
  12700. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12701. //* Execute SQL statement */
  12702. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12703. if( rc != SQLITE_OK ){
  12704. DEBUG_INFO("SQL error: %s", zErrMsg);
  12705. //sqlite3_free(zErrMsg);
  12706. }
  12707. }
  12708. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12709. {
  12710. int isSuccess = FALSE;
  12711. int ret = 0;
  12712. const char* data = "Callback function called";
  12713. char sql[200];
  12714. char zErrMsg[100];
  12715. memset(sql, 0, 200);
  12716. memset(zErrMsg, 0, 100);
  12717. //* selectFromTable */
  12718. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12719. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12720. //* Execute SQL statement */
  12721. selectSqlCount = 0;
  12722. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12723. if( ret != SQLITE_OK ){
  12724. printf("Error SQL: %s\n", zErrMsg);
  12725. }
  12726. printf("successfully select operation done\n");
  12727. memset(sql, 0, 200);
  12728. memset(zErrMsg, 0, 100);
  12729. if(selectSqlCount == 0)
  12730. {
  12731. //Insert
  12732. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12733. 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);
  12734. DEBUG_INFO("sql:%s\n", sql);
  12735. //* Execute SQL statement */
  12736. //zErrMsg = 0;
  12737. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12738. if( ret != SQLITE_OK ){
  12739. printf("SQL error: %s\n", zErrMsg);
  12740. return isSuccess;
  12741. }
  12742. DEBUG_INFO("successfully Insert records created\n");
  12743. isSuccess = TRUE;
  12744. }
  12745. else
  12746. {
  12747. //Update
  12748. //* Create merged SQL statement */
  12749. 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);
  12750. /* Execute SQL statement */
  12751. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12752. if( ret != SQLITE_OK ){
  12753. printf("SQL error: %s\n", zErrMsg);
  12754. //sqlite3_free(zErrMsg);
  12755. //sqlite3_free(sql);
  12756. return isSuccess;
  12757. }
  12758. DEBUG_INFO("Successfully operation done \n");
  12759. isSuccess = TRUE;
  12760. }
  12761. return isSuccess;
  12762. }
  12763. int GetOcppServerURL()
  12764. {
  12765. int result = FALSE;
  12766. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12767. memset(OcppHost, 0, sizeof(OcppHost));
  12768. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12769. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12770. {
  12771. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12772. #if 1
  12773. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12774. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12775. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12776. #endif
  12777. #if 0
  12778. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12779. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  12780. OcppProtocol, OcppHost, OcppTempPath);
  12781. OcppPort = 443;
  12782. #endif
  12783. result = TRUE;
  12784. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12785. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12786. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12787. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12788. goto End;
  12789. }
  12790. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12791. {
  12792. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12793. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12794. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12795. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12796. result = TRUE;
  12797. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12798. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12799. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12800. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12801. goto End;
  12802. }
  12803. else
  12804. {
  12805. strcpy(OcppHost,"");
  12806. }
  12807. End:
  12808. return result;
  12809. }
  12810. int GetOcppPath()
  12811. {
  12812. int result = FALSE;
  12813. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12814. {
  12815. if(OcppTempPath == NULL)
  12816. {
  12817. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12818. }
  12819. else
  12820. {
  12821. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12822. }
  12823. result = TRUE;
  12824. goto End;
  12825. }
  12826. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12827. {
  12828. if(OcppTempPath == NULL)
  12829. {
  12830. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12831. }
  12832. else
  12833. {
  12834. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12835. }
  12836. result = TRUE;
  12837. goto End;
  12838. }
  12839. else
  12840. {
  12841. strcpy(OcppPath,"");
  12842. }
  12843. End:
  12844. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12845. return result;
  12846. }
  12847. int GetOcppPort()
  12848. {
  12849. return OcppPort;
  12850. }
  12851. int GetOcppConnStatus(void)
  12852. {
  12853. return ShmOCPP16Data->OcppConnStatus;
  12854. }
  12855. void SetOcppConnStatus(uint8_t status)
  12856. {
  12857. ShmOCPP16Data->OcppConnStatus = status;
  12858. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12859. if(status == FALSE)
  12860. {
  12861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12862. {
  12863. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12864. }
  12865. else
  12866. {
  12867. SystemInitial = AC_QUANTITY;
  12868. }
  12869. }
  12870. }
  12871. int GetHeartBeatWithNOResponse(void)
  12872. {
  12873. return HeartBeatWithNOResponse;
  12874. }
  12875. void SetHeartBeatWithNOResponse(void)
  12876. {
  12877. HeartBeatWithNOResponse = 0;
  12878. }
  12879. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12880. /*
  12881. src 源字串的首地址(buf的地址)
  12882. separator 指定的分割字元
  12883. dest 接收子字串的陣列
  12884. num 分割後子字串的個數
  12885. */
  12886. char *pNext;
  12887. int count = 0;
  12888. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12889. return;
  12890. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12891. return;
  12892. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12893. while(pNext != NULL) {
  12894. *dest++ = pNext;
  12895. ++count;
  12896. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12897. }
  12898. *num = count;
  12899. }
  12900. int GetTransactionId(int gunindex, unsigned char idTag[])
  12901. {
  12902. char ch;
  12903. FILE *fptr1;
  12904. int temptransactionId;
  12905. char str[100]={0};
  12906. temptransactionId = 0;
  12907. /*------ Read the file ----------------*/
  12908. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12909. if (!fptr1)
  12910. {
  12911. printf(" File not found or unable to open the input file!!\n");
  12912. return temptransactionId;
  12913. }
  12914. ch=fgetc(fptr1);
  12915. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12916. rewind(fptr1);
  12917. if(ch!=EOF)
  12918. {
  12919. // printf("%c",ch);
  12920. while (fgets(str, 100, fptr1) != NULL)
  12921. {
  12922. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12923. if(str[0]=='\0')
  12924. {
  12925. break;
  12926. }
  12927. char *revbuf[8] = {0}; //存放分割後的子字串
  12928. int num = 0;//分割後子字串的個數
  12929. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12930. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12931. {
  12932. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12933. {
  12934. temptransactionId = atoi(revbuf[2]);
  12935. break;
  12936. }
  12937. }
  12938. }
  12939. }
  12940. fclose(fptr1);
  12941. /*------- End of reading ---------------*/
  12942. return temptransactionId;
  12943. }
  12944. void SetTransactionIdZero(int transactionId)
  12945. {
  12946. //TransactionId[gunindex] = 0;
  12947. char ch;
  12948. FILE *fptr1, *fptr2;
  12949. int temptransactionId = 0;
  12950. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12951. printf("\n\n Delete a specific line from a file :\n");
  12952. printf("-----------------------------------------\n");
  12953. //scanf("%s",fname);
  12954. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12955. if (!fptr1)
  12956. {
  12957. printf(" File not found or unable to open the input file!!\n");
  12958. return ;
  12959. }
  12960. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12961. if (!fptr2)
  12962. {
  12963. printf("Unable to open a temporary file to write!!\n");
  12964. fclose(fptr1);
  12965. return ;
  12966. }
  12967. ch=fgetc(fptr1);
  12968. //printf(" Now the content of the file %s is : \n",fname);
  12969. rewind(fptr1);
  12970. if(ch!=EOF)
  12971. {
  12972. // copy all contents to the temporary file except the specific line
  12973. while (fgets(str, 100, fptr1) != NULL)
  12974. {
  12975. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12976. if(str[0]=='\0')
  12977. {
  12978. break;
  12979. }
  12980. char *revbuf[8] = {0}; //存放分割後的子字串
  12981. int num = 0;//分割後子字串的個數
  12982. strcpy(strtemp, str);
  12983. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12984. if(revbuf[2][0] != '\0')
  12985. {
  12986. temptransactionId = atoi(revbuf[2]);
  12987. if(transactionId != temptransactionId)
  12988. {
  12989. fprintf(fptr2, "%s", strtemp);
  12990. }
  12991. }
  12992. }
  12993. }
  12994. fclose(fptr1);
  12995. fclose(fptr2);
  12996. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12997. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12998. /*------ Read the file ----------------*/
  12999. }
  13000. int InternetDisconnect(void)
  13001. {
  13002. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13003. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13004. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13005. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13006. }
  13007. void GetChargingProfileRequest(int gunindex)
  13008. {
  13009. mtrace();
  13010. //int connectorIdInt, durationInt;
  13011. //char chargingRateUnitStr[4]={0};
  13012. int tempdurationInt = 0;
  13013. int tempchargingProfileId = 0;
  13014. int tempstackLevel = 0;
  13015. int temptransactionId = 0;
  13016. float tempminChargingRateFloat = 0.0;
  13017. char tempchargingProfilePurposeStr[24]={0};
  13018. char tempchargingProfileKindStr[12]={0};
  13019. char temprecurrencyKindStr[8]={0};
  13020. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13021. char tempvalidToStr[28]={0};
  13022. int tempStartPeriodInt = 0;
  13023. float tempLimitInt = 0.0;//0.1;
  13024. int tempNumberPhasesInt=0;
  13025. char fname[200];
  13026. //char comfirmstr[20];
  13027. float MinChargingRate =0.0;
  13028. double diff_t;
  13029. struct tm tp;
  13030. FILE *fptr1;//, *fptr2;
  13031. int c = 0;
  13032. char * pch;
  13033. char *loc;
  13034. char sstr[200]={ 0 };
  13035. int n_chargingProfile = 0;
  13036. int n_SchedulePeriods = 0;
  13037. char SchedulePeriodList[10][200]={0};
  13038. char sLineWord[1600]={0};
  13039. char word[1000]={0};
  13040. int confirmPeriods = 0;
  13041. struct StructProfile ChargePointMaxProfile;
  13042. struct StructProfile TxDefaultProfile;
  13043. struct StructProfile TxProfile;
  13044. struct StructProfile TxDefaultProfiletemp[2]={0};
  13045. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13046. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13047. struct StructChargingProfile TxProfile_TEMP={0};
  13048. int TxDefaultProfileFileIsNull=FALSE;
  13049. int ChargePointMaxProfileIsNull=FALSE;
  13050. int TxProfileIsNull=FALSE;
  13051. // int CompositeSceduleIndex = 0;
  13052. char ChargePointMaxProfileScheduleStr[30]={0};
  13053. char TxDefaultProfileScheduleStr[30]={0};
  13054. char TxProfileScheduleStr[30]={0};
  13055. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13056. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13057. memset(&TxProfile,0,sizeof(struct StructProfile));
  13058. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13059. DEBUG_INFO("GetChargingProfileRequest\n");
  13060. //*****************************ChargePointMaxProfile******************************************/
  13061. strcpy(fname, ChargePointMaxProfile_JSON);
  13062. ChargePointMaxProfileIsNull=TRUE;
  13063. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13064. {
  13065. fptr1 = fopen(fname, "r");
  13066. int c;
  13067. c = fgetc(fptr1);
  13068. //DEBUG_INFO("c:%d\n",c);
  13069. rewind(fptr1);
  13070. if(c == EOF)
  13071. {
  13072. DEBUG_INFO("\n End of file reached.");
  13073. ChargePointMaxProfileIsNull=TRUE;
  13074. fclose(fptr1);
  13075. }
  13076. else
  13077. {
  13078. ChargePointMaxProfileIsNull=FALSE;
  13079. while(fscanf(fptr1, "%s", word) != EOF)
  13080. {
  13081. if(strcmp(word, "chargingProfileId") == 0)
  13082. {
  13083. n_chargingProfile = n_chargingProfile + 1;
  13084. }
  13085. }
  13086. rewind(fptr1);
  13087. //search Charging Profile Element
  13088. int i = 0;
  13089. int j = 0;
  13090. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13091. //***********chargingProfileId**************/
  13092. c = 0;
  13093. loc = strstr(sLineWord, "chargingProfileId");
  13094. //DEBUG_INFO("loc=%s\n",loc);
  13095. memset(sstr ,0, sizeof(sstr) );
  13096. if(loc != NULL)
  13097. {
  13098. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13099. {
  13100. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13102. c++;
  13103. }
  13104. sstr[c] = '\0';
  13105. tempchargingProfileId = atoi(sstr);
  13106. }
  13107. else
  13108. {
  13109. tempchargingProfileId = 0;
  13110. }
  13111. //***********stackLevel**************/
  13112. c = 0;
  13113. loc = strstr(sLineWord, "stackLevel");
  13114. //DEBUG_INFO("loc=%s\n",loc);
  13115. memset(sstr ,0, sizeof(sstr) );
  13116. if(loc != NULL)
  13117. {
  13118. while (loc[2+strlen("stackLevel")+c] != '\"')
  13119. {
  13120. sstr[c] = loc[2+strlen("stackLevel")+c];
  13121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13122. c++;
  13123. }
  13124. sstr[c] = '\0';
  13125. tempstackLevel = atoi(sstr);
  13126. }
  13127. else
  13128. {
  13129. tempstackLevel = 0;
  13130. }
  13131. //***********chargingProfilePurpose **************/
  13132. c = 0;
  13133. loc = strstr(sLineWord, "chargingProfilePurpose");
  13134. //DEBUG_INFO("loc=%s\n",loc);
  13135. memset(sstr ,0, sizeof(sstr) );
  13136. if(loc != NULL)
  13137. {
  13138. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13139. {
  13140. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13141. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13142. c++;
  13143. }
  13144. sstr[c] = '\0';
  13145. strcpy(tempchargingProfilePurposeStr,sstr);
  13146. }
  13147. else
  13148. {
  13149. strcpy(tempchargingProfilePurposeStr,"");
  13150. }
  13151. //***********chargingProfileKind **************/
  13152. c = 0;
  13153. loc = strstr(sLineWord, "chargingProfileKind");
  13154. //DEBUG_INFO("loc=%s\n",loc);
  13155. memset(sstr ,0, sizeof(sstr) );
  13156. if(loc != NULL)
  13157. {
  13158. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13159. {
  13160. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13161. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13162. c++;
  13163. }
  13164. sstr[c] = '\0';
  13165. strcpy(tempchargingProfileKindStr,sstr);
  13166. }
  13167. else
  13168. {
  13169. strcpy(tempchargingProfileKindStr,"");
  13170. }
  13171. //***********recurrencyKind **************/
  13172. c = 0;
  13173. loc = strstr(sLineWord, "recurrencyKind");
  13174. //DEBUG_INFO("loc=%s\n",loc);
  13175. memset(sstr ,0, sizeof(sstr) );
  13176. if(loc != NULL)
  13177. {
  13178. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13179. {
  13180. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13182. c++;
  13183. }
  13184. sstr[c] = '\0';
  13185. strcpy(temprecurrencyKindStr,sstr);
  13186. }
  13187. else
  13188. {
  13189. strcpy(temprecurrencyKindStr,"");
  13190. }
  13191. //***********validFrom**************/
  13192. c = 0;
  13193. loc = strstr(sLineWord, "validFrom");
  13194. //DEBUG_INFO("loc=%s\n",loc);
  13195. memset(sstr ,0, sizeof(sstr) );
  13196. if(loc != NULL)
  13197. {
  13198. while (loc[3+strlen("validFrom")+c] != '\"')
  13199. {
  13200. sstr[c] = loc[3+strlen("validFrom")+c];
  13201. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13202. c++;
  13203. }
  13204. sstr[c] = '\0';
  13205. strcpy(tempvalidFromStr,sstr);
  13206. }
  13207. else
  13208. {
  13209. strcpy(tempvalidFromStr,"");
  13210. }
  13211. //***********validTo **************/
  13212. c = 0;
  13213. loc = strstr(sLineWord, "validTo");
  13214. //DEBUG_INFO("loc=%s\n",loc);
  13215. memset(sstr ,0, sizeof(sstr) );
  13216. if(loc != NULL)
  13217. {
  13218. while (loc[3+strlen("validTo")+c] != '\"')
  13219. {
  13220. sstr[c] = loc[3+strlen("validTo")+c];
  13221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13222. c++;
  13223. }
  13224. sstr[c] = '\0';
  13225. strcpy(tempvalidToStr,sstr);
  13226. }
  13227. else
  13228. {
  13229. strcpy(tempvalidToStr,"");
  13230. }
  13231. //***********validFrom**************/
  13232. c = 0;
  13233. loc = strstr(sLineWord, "validFrom");
  13234. if(loc != NULL)
  13235. {
  13236. memset(sstr ,0, sizeof(sstr) );
  13237. while (loc[3+strlen("validFrom")+c] != '\"')
  13238. {
  13239. sstr[c] = loc[3+strlen("validFrom")+c];
  13240. c++;
  13241. }
  13242. sstr[c] = '\0';
  13243. strcpy(tempvalidFromStr,sstr);
  13244. }
  13245. else
  13246. {
  13247. strcpy(tempvalidFromStr,"");
  13248. }
  13249. //***********validTo **************/
  13250. c = 0;
  13251. loc = strstr(sLineWord, "validTo");
  13252. if(loc != NULL)
  13253. {
  13254. memset(sstr ,0, sizeof(sstr) );
  13255. while (loc[3+strlen("validTo")+c] != '\"')
  13256. {
  13257. sstr[c] = loc[3+strlen("validTo")+c];
  13258. c++;
  13259. }
  13260. sstr[c] = '\0';
  13261. strcpy(tempvalidToStr,sstr);
  13262. }
  13263. else
  13264. {
  13265. strcpy(tempvalidToStr,"");
  13266. }
  13267. //***********duration**************/
  13268. c = 0;
  13269. loc = strstr(sLineWord, "duration");
  13270. if(loc != NULL)
  13271. {
  13272. memset(sstr ,0, sizeof(sstr) );
  13273. while (loc[2+strlen("duration")+c] != ',')
  13274. {
  13275. sstr[c] = loc[2+strlen("duration")+c];
  13276. c++;
  13277. }
  13278. sstr[c] = '\0';
  13279. tempdurationInt = atoi(sstr);
  13280. }
  13281. else
  13282. {
  13283. tempdurationInt = 0;
  13284. }
  13285. //**********startSchedule**********/
  13286. c = 0;
  13287. loc = strstr(sLineWord, "startSchedule");
  13288. memset(sstr ,0, sizeof(sstr) );
  13289. while (loc[3+strlen("startSchedule")+c] != '\"')
  13290. {
  13291. sstr[c] = loc[3+strlen("startSchedule")+c];
  13292. c++;
  13293. }
  13294. sstr[c] = '\0';
  13295. strcpy(tempstartScheduleStr, sstr);
  13296. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13297. //**********chargingRateUnit**********/
  13298. c = 0;
  13299. loc = strstr(sLineWord, "chargingRateUnit");
  13300. memset(sstr ,0, sizeof(sstr) );
  13301. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13302. {
  13303. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13304. c++;
  13305. }
  13306. sstr[c] = '\0';
  13307. strcpy(tempchargingRateUnitStr, sstr);
  13308. //**********minChargingRate*******/
  13309. c = 0;
  13310. loc = strstr(sLineWord, "minChargingRate");
  13311. if(loc != NULL)
  13312. {
  13313. memset(sstr ,0, sizeof(sstr) );
  13314. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13315. {
  13316. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13317. c++;
  13318. }
  13319. sstr[c] = '\0';
  13320. tempminChargingRateFloat = atof(sstr);
  13321. }
  13322. else
  13323. {
  13324. tempminChargingRateFloat = 0.0;
  13325. }
  13326. //
  13327. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13328. tp.tm_isdst = -1;
  13329. time_t utc = mktime(&tp);
  13330. time_t t = time(NULL);
  13331. diff_t = difftime(t, utc);
  13332. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13333. //parsing strings to words
  13334. i = 0;
  13335. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13336. loc = loc+3+strlen("chargingSchedulePeriod");
  13337. pch = strtok(loc ,"{");
  13338. while (pch != NULL)
  13339. {
  13340. strcpy(SchedulePeriodList[i], pch);
  13341. pch = strtok (NULL, "{");
  13342. i = i + 1;
  13343. }
  13344. n_SchedulePeriods = i;
  13345. for(int i=0;i<n_SchedulePeriods;i++)
  13346. {
  13347. //*************startPeriod****************/
  13348. c = 0;
  13349. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13350. memset(sstr ,0, sizeof(sstr) );
  13351. while (loc[strlen("startPeriod")+2+c] != ',')
  13352. {
  13353. sstr[c] = loc[strlen("startPeriod")+2+c];
  13354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13355. c++;
  13356. }
  13357. sstr[c] = '\0';
  13358. tempStartPeriodInt = atoi(sstr);
  13359. //*************limit****************/
  13360. c = 0;
  13361. loc = strstr(SchedulePeriodList[i], "limit");
  13362. memset(sstr ,0, sizeof(sstr) );
  13363. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  13364. {
  13365. sstr[c] = loc[strlen("limit")+2+c];
  13366. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13367. c++;
  13368. }
  13369. sstr[c] = '\0';
  13370. tempLimitInt = atof(sstr);
  13371. //*************numberPhases****************/
  13372. c = 0;
  13373. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13374. memset(sstr ,0, sizeof(sstr) );
  13375. if(loc != NULL)
  13376. {
  13377. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  13378. {
  13379. sstr[c] = loc[strlen("numberPhases")+2+c];
  13380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13381. c++;
  13382. }
  13383. sstr[c] = '\0';
  13384. tempNumberPhasesInt = atoi(sstr);
  13385. }
  13386. else
  13387. {
  13388. tempNumberPhasesInt = 0;
  13389. }
  13390. if(j == 0)
  13391. {
  13392. ChargePointMaxProfile.Duration = tempdurationInt;
  13393. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13394. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13395. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13396. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13397. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13398. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13399. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13400. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13401. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13402. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13403. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13404. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13405. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13406. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13407. }
  13408. }
  13409. if(MinChargingRate < tempminChargingRateFloat)
  13410. {
  13411. MinChargingRate = tempminChargingRateFloat;
  13412. }
  13413. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13414. if(confirmPeriods < n_SchedulePeriods)
  13415. {
  13416. confirmPeriods = n_SchedulePeriods;
  13417. }
  13418. j = j + 1;
  13419. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13420. fclose(fptr1);
  13421. }// end else
  13422. }// the end of access file ChargePointMaxProfile
  13423. //****************************TxDefaultProfile************************************************/
  13424. memset(fname, 0, sizeof fname);
  13425. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13426. TxDefaultProfileFileIsNull=TRUE;
  13427. if((access(fname,F_OK))!=-1)
  13428. {
  13429. fptr1 = fopen(fname, "r");
  13430. c = 0;
  13431. c = fgetc(fptr1);
  13432. //DEBUG_INFO("c:%d\n",c);
  13433. rewind(fptr1);
  13434. if(c == EOF)
  13435. {
  13436. DEBUG_INFO("\n End of file reached.");
  13437. TxDefaultProfileFileIsNull=TRUE;
  13438. fclose(fptr1);
  13439. }
  13440. else
  13441. {
  13442. TxDefaultProfileFileIsNull=FALSE;
  13443. while(fscanf(fptr1, "%s", word) != EOF)
  13444. {
  13445. if(strcmp(word, "chargingProfileId") == 0)
  13446. {
  13447. n_chargingProfile = n_chargingProfile + 1;
  13448. }
  13449. }
  13450. rewind(fptr1);
  13451. //search Charging Profile Element
  13452. int i = 0;
  13453. int j = 0;
  13454. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13455. {
  13456. #if 0
  13457. //***********connectorId****************/
  13458. c = 0;
  13459. loc = strstr(sLineWord, "connectorId");
  13460. memset(sstr ,0, sizeof(sstr) );
  13461. while (loc[strlen("connectorId")+2+c] != ',')
  13462. {
  13463. sstr[c] = loc[strlen("connectorId")+2+c];
  13464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13465. c++;
  13466. }
  13467. sstr[c] = '\0';
  13468. tempconnectorIdInt = atoi(sstr);
  13469. #endif
  13470. //***********chargingProfileId**************/
  13471. c = 0;
  13472. loc = strstr(sLineWord, "chargingProfileId");
  13473. //DEBUG_INFO("loc=%s\n",loc);
  13474. memset(sstr ,0, sizeof(sstr) );
  13475. if(loc != NULL)
  13476. {
  13477. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13478. {
  13479. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13481. c++;
  13482. }
  13483. sstr[c] = '\0';
  13484. tempchargingProfileId = atoi(sstr);
  13485. }
  13486. else
  13487. {
  13488. tempchargingProfileId = 0;
  13489. }
  13490. //***********stackLevel**************/
  13491. c = 0;
  13492. loc = strstr(sLineWord, "stackLevel");
  13493. //DEBUG_INFO("loc=%s\n",loc);
  13494. memset(sstr ,0, sizeof(sstr) );
  13495. if(loc != NULL)
  13496. {
  13497. while (loc[2+strlen("stackLevel")+c] != '\"')
  13498. {
  13499. sstr[c] = loc[2+strlen("stackLevel")+c];
  13500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13501. c++;
  13502. }
  13503. sstr[c] = '\0';
  13504. tempstackLevel = atoi(sstr);
  13505. }
  13506. else
  13507. {
  13508. tempstackLevel = 0;
  13509. }
  13510. //***********chargingProfilePurpose **************/
  13511. c = 0;
  13512. loc = strstr(sLineWord, "chargingProfilePurpose");
  13513. //DEBUG_INFO("loc=%s\n",loc);
  13514. memset(sstr ,0, sizeof(sstr) );
  13515. if(loc != NULL)
  13516. {
  13517. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13518. {
  13519. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13521. c++;
  13522. }
  13523. sstr[c] = '\0';
  13524. strcpy(tempchargingProfilePurposeStr,sstr);
  13525. }
  13526. else
  13527. {
  13528. strcpy(tempchargingProfilePurposeStr,"");
  13529. }
  13530. //***********chargingProfileKind **************/
  13531. c = 0;
  13532. loc = strstr(sLineWord, "chargingProfileKind");
  13533. //DEBUG_INFO("loc=%s\n",loc);
  13534. memset(sstr ,0, sizeof(sstr) );
  13535. if(loc != NULL)
  13536. {
  13537. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13538. {
  13539. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13540. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13541. c++;
  13542. }
  13543. sstr[c] = '\0';
  13544. strcpy(tempchargingProfileKindStr,sstr);
  13545. }
  13546. else
  13547. {
  13548. strcpy(tempchargingProfileKindStr,"");
  13549. }
  13550. //***********recurrencyKind **************/
  13551. c = 0;
  13552. loc = strstr(sLineWord, "recurrencyKind");
  13553. //DEBUG_INFO("loc=%s\n",loc);
  13554. memset(sstr ,0, sizeof(sstr) );
  13555. if(loc != NULL)
  13556. {
  13557. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13558. {
  13559. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13561. c++;
  13562. }
  13563. sstr[c] = '\0';
  13564. strcpy(temprecurrencyKindStr,sstr);
  13565. }
  13566. else
  13567. {
  13568. strcpy(temprecurrencyKindStr,"");
  13569. }
  13570. //***********validFrom**************/
  13571. c = 0;
  13572. loc = strstr(sLineWord, "validFrom");
  13573. if(loc != NULL)
  13574. {
  13575. memset(sstr ,0, sizeof(sstr) );
  13576. while (loc[3+strlen("validFrom")+c] != '\"')
  13577. {
  13578. sstr[c] = loc[3+strlen("validFrom")+c];
  13579. c++;
  13580. }
  13581. sstr[c] = '\0';
  13582. strcpy(tempvalidFromStr,sstr);
  13583. }
  13584. else
  13585. {
  13586. strcpy(tempvalidFromStr,"");
  13587. }
  13588. //***********validTo **************/
  13589. c = 0;
  13590. loc = strstr(sLineWord, "validTo");
  13591. if(loc != NULL)
  13592. {
  13593. memset(sstr ,0, sizeof(sstr) );
  13594. while (loc[3+strlen("validTo")+c] != '\"')
  13595. {
  13596. sstr[c] = loc[3+strlen("validTo")+c];
  13597. c++;
  13598. }
  13599. sstr[c] = '\0';
  13600. strcpy(tempvalidToStr,sstr);
  13601. }
  13602. else
  13603. {
  13604. strcpy(tempvalidToStr,"");
  13605. }
  13606. //***********duration**************/
  13607. c = 0;
  13608. loc = strstr(sLineWord, "duration");
  13609. if(loc != NULL)
  13610. {
  13611. memset(sstr ,0, sizeof(sstr) );
  13612. while (loc[2+strlen("duration")+c] != ',')
  13613. {
  13614. sstr[c] = loc[2+strlen("duration")+c];
  13615. c++;
  13616. }
  13617. sstr[c] = '\0';
  13618. tempdurationInt = atoi(sstr);
  13619. }
  13620. else
  13621. {
  13622. tempdurationInt = 0;
  13623. }
  13624. //**********startSchedule**********/
  13625. c = 0;
  13626. loc = strstr(sLineWord, "startSchedule");
  13627. memset(sstr ,0, sizeof(sstr) );
  13628. while (loc[3+strlen("startSchedule")+c] != '\"')
  13629. {
  13630. sstr[c] = loc[3+strlen("startSchedule")+c];
  13631. c++;
  13632. }
  13633. sstr[c] = '\0';
  13634. strcpy(tempstartScheduleStr, sstr);
  13635. strcpy(TxDefaultProfileScheduleStr, sstr);
  13636. //**********chargingRateUnit**********/
  13637. c = 0;
  13638. loc = strstr(sLineWord, "chargingRateUnit");
  13639. memset(sstr ,0, sizeof(sstr) );
  13640. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13641. {
  13642. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13643. c++;
  13644. }
  13645. sstr[c] = '\0';
  13646. strcpy(tempchargingRateUnitStr, sstr);
  13647. //**********minChargingRate*******/
  13648. c = 0;
  13649. loc = strstr(sLineWord, "minChargingRate");
  13650. if(loc != NULL)
  13651. {
  13652. memset(sstr ,0, sizeof(sstr) );
  13653. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13654. {
  13655. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13656. c++;
  13657. }
  13658. sstr[c] = '\0';
  13659. tempminChargingRateFloat = atof(sstr);
  13660. }
  13661. else
  13662. {
  13663. tempminChargingRateFloat = 0.0;
  13664. }
  13665. //
  13666. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13667. tp.tm_isdst = -1;
  13668. time_t utc = mktime(&tp);
  13669. time_t t = time(NULL);
  13670. diff_t = difftime(t, utc);
  13671. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13672. //parsing strings to words
  13673. i = 0;
  13674. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13675. loc = loc+3+strlen("chargingSchedulePeriod");
  13676. pch = strtok(loc ,"{");
  13677. while (pch != NULL)
  13678. {
  13679. strcpy(SchedulePeriodList[i], pch);
  13680. pch = strtok (NULL, "{");
  13681. i = i + 1;
  13682. }
  13683. n_SchedulePeriods = i;
  13684. for(int i=0;i<n_SchedulePeriods;i++)
  13685. {
  13686. //*************startPeriod****************/
  13687. c = 0;
  13688. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13689. memset(sstr ,0, sizeof(sstr) );
  13690. while (loc[strlen("startPeriod")+2+c] != ',')
  13691. {
  13692. sstr[c] = loc[strlen("startPeriod")+2+c];
  13693. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13694. c++;
  13695. }
  13696. sstr[c] = '\0';
  13697. tempStartPeriodInt = atoi(sstr);
  13698. //*************limit****************/
  13699. c = 0;
  13700. loc = strstr(SchedulePeriodList[i], "limit");
  13701. memset(sstr ,0, sizeof(sstr) );
  13702. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  13703. {
  13704. sstr[c] = loc[strlen("limit")+2+c];
  13705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13706. c++;
  13707. }
  13708. sstr[c] = '\0';
  13709. tempLimitInt = atof(sstr);
  13710. //*************numberPhases****************/
  13711. c = 0;
  13712. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13713. memset(sstr ,0, sizeof(sstr) );
  13714. if(loc != NULL)
  13715. {
  13716. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  13717. {
  13718. sstr[c] = loc[strlen("numberPhases")+2+c];
  13719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13720. c++;
  13721. }
  13722. sstr[c] = '\0';
  13723. tempNumberPhasesInt = atoi(sstr);
  13724. }
  13725. else
  13726. {
  13727. tempNumberPhasesInt = 0;
  13728. }
  13729. if(j == 0)
  13730. {
  13731. TxDefaultProfile.Duration = tempdurationInt;
  13732. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13733. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13734. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13735. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13736. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13737. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13738. TxDefaultProfile_TEMP.TransactionId = 0;
  13739. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13740. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13741. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13742. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13743. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13744. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13745. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13746. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13747. }
  13748. else
  13749. {
  13750. //other stack level charging Profile
  13751. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13752. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13753. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13754. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13755. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13756. }
  13757. }
  13758. if(MinChargingRate < tempminChargingRateFloat)
  13759. {
  13760. MinChargingRate = tempminChargingRateFloat;
  13761. }
  13762. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13763. if(confirmPeriods < n_SchedulePeriods)
  13764. confirmPeriods = n_SchedulePeriods;
  13765. j = j + 1;
  13766. }
  13767. fclose(fptr1);
  13768. //Stacking Charging Profiles
  13769. for(int l=0; l <(j-1) ;l++)
  13770. {
  13771. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13772. {
  13773. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13774. {
  13775. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13776. {
  13777. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13778. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13779. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13780. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13781. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13782. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13783. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13784. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13785. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13786. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13787. }
  13788. else
  13789. {
  13790. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13791. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13792. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13793. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13794. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13795. }
  13796. }
  13797. }
  13798. }//end of Stacking Charging Profiles
  13799. }// end else
  13800. }// the end of ACCESS TxDefaultProfile
  13801. //****************************TxProfile************************************************/
  13802. memset(fname, 0, sizeof fname);
  13803. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13804. TxProfileIsNull=TRUE;
  13805. if((access(fname,F_OK))!=-1)
  13806. {
  13807. fptr1 = fopen(fname, "r");
  13808. c = 0;
  13809. c = fgetc(fptr1);
  13810. //DEBUG_INFO("c:%d\n",c);
  13811. rewind(fptr1);
  13812. if(c == EOF)
  13813. {
  13814. DEBUG_INFO("\n End of file reached.");
  13815. TxProfileIsNull=TRUE;
  13816. fclose(fptr1);
  13817. }
  13818. else
  13819. {
  13820. TxProfileIsNull=FALSE;
  13821. while(fscanf(fptr1, "%s", word) != EOF)
  13822. {
  13823. if(strcmp(word, "chargingProfileId") == 0)
  13824. {
  13825. n_chargingProfile = n_chargingProfile + 1;
  13826. }
  13827. }
  13828. rewind(fptr1);
  13829. //search Charging Profile Element
  13830. int i= 0;
  13831. int j= 0;
  13832. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13833. #if 0
  13834. /***********connectorId****************/
  13835. c = 0;
  13836. loc = strstr(sLineWord, "connectorId");
  13837. memset(sstr ,0, sizeof(sstr) );
  13838. while (loc[strlen("connectorId")+2+c] != ',')
  13839. {
  13840. sstr[c] = loc[strlen("connectorId")+2+c];
  13841. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13842. c++;
  13843. }
  13844. sstr[c] = '\0';
  13845. tempconnectorIdInt = atoi(sstr);
  13846. #endif
  13847. //***********chargingProfileId**************/
  13848. c = 0;
  13849. loc = strstr(sLineWord, "chargingProfileId");
  13850. memset(sstr ,0, sizeof(sstr) );
  13851. if(loc != NULL)
  13852. {
  13853. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13854. {
  13855. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13857. c++;
  13858. }
  13859. sstr[c] = '\0';
  13860. tempchargingProfileId = atoi(sstr);
  13861. }
  13862. else
  13863. {
  13864. tempchargingProfileId = 0;
  13865. }
  13866. //***********transactionId **************/
  13867. c = 0;
  13868. loc = strstr(sLineWord, "transactionId");
  13869. //DEBUG_INFO("loc=%s\n",loc);
  13870. memset(sstr ,0, sizeof(sstr) );
  13871. if(loc != NULL)
  13872. {
  13873. while (loc[2+strlen("transactionId")+c] != '\"')
  13874. {
  13875. sstr[c] = loc[2+strlen("transactionId")+c];
  13876. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13877. c++;
  13878. }
  13879. sstr[c] = '\0';
  13880. temptransactionId = atoi(sstr);
  13881. }
  13882. else
  13883. {
  13884. temptransactionId = 0;
  13885. }
  13886. //***********stackLevel**************/
  13887. c = 0;
  13888. loc = strstr(sLineWord, "stackLevel");
  13889. //DEBUG_INFO("loc=%s\n",loc);
  13890. memset(sstr ,0, sizeof(sstr) );
  13891. if(loc != NULL)
  13892. {
  13893. while (loc[2+strlen("stackLevel")+c] != '\"')
  13894. {
  13895. sstr[c] = loc[2+strlen("stackLevel")+c];
  13896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13897. c++;
  13898. }
  13899. sstr[c] = '\0';
  13900. tempstackLevel = atoi(sstr);
  13901. }
  13902. else
  13903. {
  13904. tempstackLevel = 0;
  13905. }
  13906. //***********chargingProfilePurpose **************/
  13907. c = 0;
  13908. loc = strstr(sLineWord, "chargingProfilePurpose");
  13909. //DEBUG_INFO("loc=%s\n",loc);
  13910. memset(sstr ,0, sizeof(sstr) );
  13911. if(loc != NULL)
  13912. {
  13913. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13914. {
  13915. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13916. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13917. c++;
  13918. }
  13919. sstr[c] = '\0';
  13920. strcpy(tempchargingProfilePurposeStr,sstr);
  13921. }
  13922. else
  13923. {
  13924. strcpy(tempchargingProfilePurposeStr,"");
  13925. }
  13926. //***********chargingProfileKind **************/
  13927. c = 0;
  13928. loc = strstr(sLineWord, "chargingProfileKind");
  13929. //DEBUG_INFO("loc=%s\n",loc);
  13930. memset(sstr ,0, sizeof(sstr) );
  13931. if(loc != NULL)
  13932. {
  13933. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13934. {
  13935. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13937. c++;
  13938. }
  13939. sstr[c] = '\0';
  13940. strcpy(tempchargingProfileKindStr,sstr);
  13941. }
  13942. else
  13943. {
  13944. strcpy(tempchargingProfileKindStr,"");
  13945. }
  13946. //***********recurrencyKind **************/
  13947. c = 0;
  13948. loc = strstr(sLineWord, "recurrencyKind");
  13949. //DEBUG_INFO("loc=%s\n",loc);
  13950. memset(sstr ,0, sizeof(sstr) );
  13951. if(loc != NULL)
  13952. {
  13953. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13954. {
  13955. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13957. c++;
  13958. }
  13959. sstr[c] = '\0';
  13960. strcpy(temprecurrencyKindStr,sstr);
  13961. }
  13962. else
  13963. {
  13964. strcpy(temprecurrencyKindStr,"");
  13965. }
  13966. //***********validFrom**************/
  13967. c = 0;
  13968. loc = strstr(sLineWord, "validFrom");
  13969. if(loc != NULL)
  13970. {
  13971. memset(sstr ,0, sizeof(sstr) );
  13972. while (loc[3+strlen("validFrom")+c] != '\"')
  13973. {
  13974. sstr[c] = loc[3+strlen("validFrom")+c];
  13975. c++;
  13976. }
  13977. sstr[c] = '\0';
  13978. strcpy(tempvalidFromStr,sstr);
  13979. }
  13980. else
  13981. {
  13982. strcpy(tempvalidFromStr,"");
  13983. }
  13984. //***********validTo**************/
  13985. c = 0;
  13986. loc = strstr(sLineWord, "validTo");
  13987. if(loc != NULL)
  13988. {
  13989. memset(sstr ,0, sizeof(sstr) );
  13990. while (loc[3+strlen("validTo")+c] != '\"')
  13991. {
  13992. sstr[c] = loc[3+strlen("validTo")+c];
  13993. c++;
  13994. }
  13995. sstr[c] = '\0';
  13996. strcpy(tempvalidToStr,sstr);
  13997. }
  13998. else
  13999. {
  14000. strcpy(tempvalidToStr,"");
  14001. }
  14002. //***********duration**************/
  14003. c = 0;
  14004. loc = strstr(sLineWord, "duration");
  14005. //DEBUG_INFO("loc=%s\n",loc);
  14006. memset(sstr ,0, sizeof(sstr) );
  14007. if(loc != NULL)
  14008. {
  14009. while (loc[2+strlen("duration")+c] != '\"')
  14010. {
  14011. sstr[c] = loc[2+strlen("duration")+c];
  14012. c++;
  14013. }
  14014. sstr[c] = '\0';
  14015. tempdurationInt = atoi(sstr);
  14016. }
  14017. else
  14018. {
  14019. tempdurationInt = 0;
  14020. }
  14021. //**********startSchedule**********/
  14022. c = 0;
  14023. loc = strstr(sLineWord, "startSchedule");
  14024. memset(sstr ,0, sizeof(sstr) );
  14025. while (loc[3+strlen("startSchedule")+c] != '\"')
  14026. {
  14027. sstr[c] = loc[3+strlen("startSchedule")+c];
  14028. c++;
  14029. }
  14030. sstr[c] = '\0';
  14031. strcpy(tempstartScheduleStr, sstr);
  14032. strcpy(TxProfileScheduleStr, sstr);
  14033. //**********chargingRateUnit**********/
  14034. c = 0;
  14035. loc = strstr(sLineWord, "chargingRateUnit");
  14036. memset(sstr ,0, sizeof(sstr) );
  14037. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14038. {
  14039. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14040. c++;
  14041. }
  14042. sstr[c] = '\0';
  14043. strcpy(tempchargingRateUnitStr, sstr);
  14044. //**********minChargingRate*******/
  14045. c = 0;
  14046. loc = strstr(sLineWord, "minChargingRate");
  14047. if(loc != NULL)
  14048. {
  14049. memset(sstr ,0, sizeof(sstr) );
  14050. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14051. {
  14052. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14053. c++;
  14054. }
  14055. sstr[c] = '\0';
  14056. tempminChargingRateFloat = atof(sstr);
  14057. }
  14058. else
  14059. {
  14060. tempminChargingRateFloat = 0.0;
  14061. }
  14062. //
  14063. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14064. tp.tm_isdst = -1;
  14065. time_t utc = mktime(&tp);
  14066. time_t t = time(NULL);
  14067. diff_t = difftime(t, utc);
  14068. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14069. //parsing strings to words
  14070. i = 0;
  14071. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14072. loc = loc+3+strlen("chargingSchedulePeriod");
  14073. pch = strtok(loc ,"{");
  14074. while (pch != NULL)
  14075. {
  14076. strcpy(SchedulePeriodList[i], pch);
  14077. pch = strtok (NULL, "{");
  14078. i = i + 1;
  14079. }
  14080. n_SchedulePeriods = i;
  14081. for(int i=0;i<n_SchedulePeriods;i++)
  14082. {
  14083. //*************startPeriod****************/
  14084. c = 0;
  14085. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14086. memset(sstr ,0, sizeof(sstr) );
  14087. while (loc[strlen("startPeriod")+2+c] != ',')
  14088. {
  14089. sstr[c] = loc[strlen("startPeriod")+2+c];
  14090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14091. c++;
  14092. }
  14093. sstr[c] = '\0';
  14094. tempStartPeriodInt = atoi(sstr);
  14095. //*************limit****************/
  14096. c = 0;
  14097. loc = strstr(SchedulePeriodList[i], "limit");
  14098. memset(sstr ,0, sizeof(sstr) );
  14099. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14100. {
  14101. sstr[c] = loc[strlen("limit")+2+c];
  14102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14103. c++;
  14104. }
  14105. sstr[c] = '\0';
  14106. tempLimitInt = atof(sstr);
  14107. //*************numberPhases****************/
  14108. c = 0;
  14109. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14110. memset(sstr ,0, sizeof(sstr) );
  14111. if(loc != NULL)
  14112. {
  14113. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14114. {
  14115. sstr[c] = loc[strlen("numberPhases")+2+c];
  14116. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14117. c++;
  14118. }
  14119. sstr[c] = '\0';
  14120. tempNumberPhasesInt = atoi(sstr);
  14121. }
  14122. else
  14123. {
  14124. tempNumberPhasesInt = 0;
  14125. }
  14126. //TxProfile.Duration = durationInt;
  14127. TxProfile.TotalPeriod = n_SchedulePeriods;
  14128. TxProfile.Period[i].Limit = tempLimitInt;
  14129. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14130. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14131. }
  14132. if(MinChargingRate < tempminChargingRateFloat)
  14133. {
  14134. MinChargingRate = tempminChargingRateFloat;
  14135. }
  14136. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14137. if(confirmPeriods < n_SchedulePeriods)
  14138. confirmPeriods = n_SchedulePeriods;
  14139. if(j == 0)
  14140. {
  14141. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14142. TxProfile_TEMP.StackLevel = tempstackLevel;
  14143. TxProfile_TEMP.TransactionId = 0;
  14144. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14145. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14146. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14147. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14148. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14149. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14150. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14151. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14152. }
  14153. }
  14154. fclose(fptr1);
  14155. }
  14156. }// the end of ACCESS TxProfile
  14157. //-----------------------------------------------CompositeSchedule--------------------------//
  14158. int period=0;
  14159. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14160. {
  14161. //TxProfile
  14162. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14163. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14164. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14165. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14166. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14167. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14168. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14169. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14170. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14173. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14174. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14175. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14176. {
  14177. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14178. {
  14179. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14180. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14181. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14182. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14183. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14184. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14185. period = period + 1;
  14186. }
  14187. else
  14188. {
  14189. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14190. {
  14191. }
  14192. else
  14193. {
  14194. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14195. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14196. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14197. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14198. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14199. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14200. period = period + 1;
  14201. }
  14202. }
  14203. }
  14204. struct tm tp;
  14205. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14206. tp.tm_isdst = -1;
  14207. time_t utc = mktime(&tp);
  14208. time_t t = time(NULL);
  14209. double diff_f = difftime(t, utc);
  14210. int diff_i;// = (int)diff_f;
  14211. int quotient; // = diff_i / 86400;//86400 seconds/day
  14212. if(diff_f >= 0)
  14213. {
  14214. diff_i = (int)diff_f;
  14215. quotient = diff_i / 86400;//86400 seconds/day
  14216. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14217. {
  14218. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14219. {
  14220. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14221. {
  14222. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14223. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14224. }
  14225. else
  14226. {
  14227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14228. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14229. }
  14230. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14232. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14233. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14234. period = period + 1;
  14235. }
  14236. }
  14237. }// end of if(diff_f >= 0)
  14238. }
  14239. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14240. {
  14241. //TxDefaultProfile
  14242. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14243. struct tm tp;
  14244. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14245. tp.tm_isdst = -1;
  14246. time_t utc = mktime(&tp);
  14247. time_t t = time(NULL);
  14248. double diff_f = difftime(t, utc);
  14249. int diff_i;// = (int)diff_f;
  14250. int quotient; // = diff_i / 86400;//86400 seconds/day
  14251. int remainder;
  14252. //---- Define StartSchedule----/
  14253. struct tm *gtime;
  14254. time_t now;
  14255. char buf[28];
  14256. //---Read the current system time---/
  14257. time(&now);
  14258. //---Convert the system time to GMT (now UTC)---/
  14259. gtime = gmtime(&now);
  14260. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14261. if(diff_f >= 0)
  14262. {
  14263. diff_i = (int)diff_f;
  14264. quotient = diff_i / 86400;//86400 seconds/day
  14265. remainder = diff_i % 86400;
  14266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14267. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14268. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14271. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14272. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14273. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14274. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14275. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14276. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14277. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14278. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14279. {
  14280. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14281. {
  14282. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14283. {
  14284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14287. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14288. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14289. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14290. period = period + 1;
  14291. }
  14292. else
  14293. {
  14294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14297. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14298. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14299. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14300. period = period + 1;
  14301. }
  14302. }
  14303. }
  14304. } // end of diff_f >= 0
  14305. }
  14306. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14307. {
  14308. //TxDefaultProfile
  14309. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14310. struct tm tp;
  14311. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14312. tp.tm_isdst = -1;
  14313. time_t utc = mktime(&tp);
  14314. time_t t = time(NULL);
  14315. double diff_f = difftime(t, utc);
  14316. int diff_i;// = (int)diff_f;
  14317. int quotient; // = diff_i / 86400;//86400 seconds/day
  14318. int remainder;
  14319. //---- Define StartSchedule----/
  14320. struct tm *gtime;
  14321. time_t now;
  14322. char buf[28];
  14323. //---Read the current system time---/
  14324. time(&now);
  14325. //---Convert the system time to GMT (now UTC)---/
  14326. gtime = gmtime(&now);
  14327. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14328. if(diff_f >= 0)
  14329. {
  14330. diff_i = (int)diff_f;
  14331. quotient = diff_i / 86400;//86400 seconds/day
  14332. remainder = diff_i % 86400;
  14333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14334. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14335. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14336. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14341. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14343. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14344. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14345. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14346. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14347. {
  14348. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14349. {
  14350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14351. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14352. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14353. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14354. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14355. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14356. period = period + 1;
  14357. }
  14358. }
  14359. } //end of diff_f >= 0
  14360. }
  14361. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14362. {
  14363. //ChargePointMaxProfile
  14364. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14366. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14367. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14368. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14370. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14371. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14372. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14373. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14374. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14375. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14376. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14377. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14378. {
  14379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14382. period = period + 1;
  14383. }
  14384. }
  14385. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14386. {
  14387. //TxProfile Daily
  14388. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14394. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14395. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14396. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14397. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14400. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14401. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14402. {
  14403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14406. }
  14407. }
  14408. confirmPeriods = period;
  14409. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14410. 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,"
  14411. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14412. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14413. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14414. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14415. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14416. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14417. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14418. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14419. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14420. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14421. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14422. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14423. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14426. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14427. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14428. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14429. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14430. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14431. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14432. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14433. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14439. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14443. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14445. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14446. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14447. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14451. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14454. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14455. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14456. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14457. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14459. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14463. }
  14464. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14465. {
  14466. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14467. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14468. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14469. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14470. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14471. }
  14472. int GetWebSocketPingInterval(void)
  14473. {
  14474. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14475. }
  14476. int GetServerSign(void)
  14477. {
  14478. return server_sign;
  14479. }
  14480. void SetServerSign(int value)
  14481. {
  14482. server_sign = value;
  14483. }
  14484. int GetBootNotificationInterval(void)
  14485. {
  14486. return BootNotificationInterval;
  14487. }
  14488. int GetInternetConn(void)
  14489. {
  14490. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14491. }
  14492. void InitialSystemValue(void)
  14493. {
  14494. server_cycle_Status = 120;
  14495. gunTotalNumber=0;
  14496. localversion=0;
  14497. BootNotificationInterval = 0;
  14498. authorizeRetryTimes = 0;
  14499. GunStatusInterval = 10;
  14500. TransactionMessageAttemptsValue = 0;
  14501. TransactionMessageRetryIntervalValue = 0;
  14502. HeartBeatWithNOResponse = 0;
  14503. HeartBeatCountPerHour = 0;
  14504. HeartBeatWaitTime = 10;
  14505. FirstHeartBeat = 0;
  14506. FirmwareStatusNotificationStatus = 3; // Idle
  14507. DiagnosticsStatusNotificationStatus = 0; // Idle
  14508. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  14509. memset(statusModeChage, 0, sizeof(statusModeChage));
  14510. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  14511. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  14512. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  14513. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  14514. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  14515. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  14516. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  14517. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  14518. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  14519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14520. {
  14521. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  14522. DEBUG_INFO("DC ...\n");
  14523. }
  14524. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14525. {
  14526. SystemInitial = AC_QUANTITY;
  14527. DEBUG_INFO("AC ...\n");
  14528. }
  14529. //Status / ConnectorPlugIn Setting
  14530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14531. {
  14532. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14533. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14534. }
  14535. for (int index = 0; index < CCS_QUANTITY; index++)
  14536. {
  14537. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14538. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14539. }
  14540. for (int index = 0; index < GB_QUANTITY; index++)
  14541. {
  14542. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14543. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14544. }
  14545. for (int index = 0; index < AC_QUANTITY; index++)
  14546. {
  14547. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14548. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14549. }
  14550. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14551. {
  14552. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14553. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14554. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14555. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14556. }
  14557. // Charger PRE_SYS_MODE
  14558. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  14559. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14560. clientTime.Heartbeat=time((time_t*)NULL);
  14561. }
  14562. void LWS_Send(char * str)
  14563. {
  14564. //=====================================================
  14565. // Check InternetConn 0: disconnected, 1: connected
  14566. //====================================================
  14567. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14568. {
  14569. DEBUG_INFO("\n offline now !!!\n");
  14570. return;
  14571. }
  14572. pthread_mutex_lock(&lock);
  14573. memset(SendBuffer,0,SendBufLen);
  14574. sprintf((char *)SendBuffer, "%s", str);
  14575. pthread_mutex_unlock(&lock);
  14576. lws_callback_on_writable(wsi_client);
  14577. lws_service(context, 10000);//timeout_ms
  14578. }